perf(app): stop unbounded WASM heap growth and idle-CPU churn (#1721)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-18 18:31:28 +02:00
1 parent fa71eb8682
commit 9e89539f0a
8 files changed
+205 -62

No files matched your search

@@ -0,0 +1,35 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
export interface TrackedRecipientSnapshot {
readonly recipientIds: ReadonlyArray<string>;
}
export interface TrackedRecipientUser {
readonly username: string;
readonly globalName?: string | null;
}
/**
* Builds the MobX tracking key for group-DM display names.
*
* Only the recipients of tracked group DMs are read, so the observing reaction
* depends on those users alone rather than on the whole (unbounded) user cache.
* Reading a recipient that is not cached yet still registers a dependency on
* that key, so a user arriving later re-triggers the reaction.
*
* Kept as a standalone function rather than a class method because
* makeAutoObservable converts methods into actions, and actions run untracked.
*/
export const trackedRecipientNameKey = (
snapshots: ReadonlyMap<string, TrackedRecipientSnapshot>,
users: Record<string, TrackedRecipientUser | undefined>,
): string => {
const parts: Array<[string, string, string]> = [];
for (const snapshot of snapshots.values()) {
for (const recipientId of snapshot.recipientIds) {
const user = users[recipientId];
parts.push([recipientId, user?.username ?? '', user?.globalName ?? '']);
}
}
return JSON.stringify(parts);
};