perf(app): cut idle renderer CPU and unbounded memory growth (#1724)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-18 23:13:42 +02:00
1 parent b4a5eb77a8
commit 5660972c71
13 files changed
+453 -345

No files matched your search

+16 -3
View File
@@ -55,6 +55,7 @@ function isPublicOnlyCurrentUserPayload(user: WireUser): boolean {
class Users {
users: Record<string, User> = {};
userCount = 0;
constructor() {
makeAutoObservable(this, {}, {autoBind: true});
@@ -98,6 +99,7 @@ class Users {
this.users = {
[currentUser.id]: userRecord,
};
this.userCount = 1;
if (!userRecord.isClaimed()) {
setTimeout(async () => {
openClaimAccountModal();
@@ -121,7 +123,18 @@ class Users {
) {
return;
}
this.users[user.id] = existingUser ? existingUser.withUpdates(user, options) : new User(user);
this.storeUser(existingUser, existingUser ? existingUser.withUpdates(user, options) : new User(user));
}
private storeUser(existingUser: User | undefined, nextUser: User): void {
if (existingUser) {
if (existingUser.equals(nextUser)) {
return;
}
} else {
this.userCount += 1;
}
this.users[nextUser.id] = nextUser;
}
cacheUsers(
@@ -137,14 +150,14 @@ class Users {
if (user.id === this.currentUserId && existingUser && isPublicOnlyCurrentUserPayload(user)) {
continue;
}
this.users[user.id] = existingUser ? existingUser.withUpdates(user) : new User(user);
this.storeUser(existingUser, existingUser ? existingUser.withUpdates(user) : new User(user));
}
});
}
subscribe(callback: () => void): () => void {
return reaction(
() => Object.keys(this.users).length,
() => this.userCount,
() => callback(),
{fireImmediately: true},
);