Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: improve data handling performance in frontend #19

Open
0xLE opened this issue Sep 1, 2024 · 0 comments
Open

Feat: improve data handling performance in frontend #19

0xLE opened this issue Sep 1, 2024 · 0 comments
Labels
area: frontend 🌐 enhancement ✨ New feature or request p2 - medium Medium importance

Comments

@0xLE
Copy link
Collaborator

0xLE commented Sep 1, 2024

Currently, the frontend performs a full computation on every state change done to the teamFlagStatusAtom:

// TODO: Add tiered caching? We are aggregating everything every time 'teamFlagStatusAtom' updates.
// Premature optimization here can lead to inconsistent aggregation. We have to deeal with status updates,
// purging and the message delivery order.
export const flagStatusAggregateAtom = atom((get) => {
const flagStatus = get(teamFlagStatusAtom);
let count = 0;
const map = new Map<FLAG_CODE, number>();
// We probably don't want to do FP here to avoid a lot of extra allocations
for (const [_, serviceMap] of Object.entries(flagStatus)) {
for (const [_, serviceFlags] of Object.entries(serviceMap)) {
for (const [_, status] of Object.entries(serviceFlags)) {
const key = status.status ?? FLAG_CODE.Pending;
map.set(key, (map.get(key) ?? 0) + 1);
++count;
}
}
}
return {
count,
statusMap: map,
};
});

Each state change will cause the frontend to recompute the entire aggregation, having a runtime complexity of O(|F|) where F is the set of flags. Frequent updates will result in a performance degradation.

@0xLE 0xLE added enhancement ✨ New feature or request p2 - medium Medium importance area: frontend 🌐 labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: frontend 🌐 enhancement ✨ New feature or request p2 - medium Medium importance
Projects
None yet
Development

No branches or pull requests

1 participant