perf(sessions): coalesce eager-fetch progress and memoize list roots - #563
Open
RonenMars wants to merge 1 commit into
Open
perf(sessions): coalesce eager-fetch progress and memoize list roots#563RonenMars wants to merge 1 commit into
RonenMars wants to merge 1 commit into
Conversation
The Hub eager-fetches every sessions/conversations page for every server on each refresh, and both hooks wrote loaded/total to state on every page tick — 15-20 full re-renders of the Hub root per refresh while showing cached data. Coalesce those writes with useThrottledCallback (250ms, trailing flush on completion so the final counter stays exact) in useEagerSessions and useEagerConversations. Wrap the four list roots (TreeSessionsList, ProjectHubList, ClassicSessionsList, MergedClassicList) in React.memo so stable-prop drain ticks skip re-running the list for tree, hub, and classic views alike. No behavior change: memo only skips re-renders when props are shallow-equal, and every list prop is a fresh ref from useMemo/state.
This was referenced Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope (partial improvement — not the full fix)
This PR paces two sources of re-render churn on the Hub during the "Showing cached data — syncing" state, but on-device measurement (see #564 / #565) showed it does not by itself stop the sustained re-render loop.
Treat it as a smaller, complementary improvement to the root-cause fixes in #566, not as "the fix" for the slow syncing state.
What it does
setStateinuseEagerSessionsanduseEagerConversationswithuseThrottledCallback(250 ms,.flush()on completion so the final counter stays exact).This collapses the per-page progress bursts from ~15-20 root re-renders per refresh to a handful, and applies to all three views because the hooks live once at the Hub root.
TreeSessionsList,ProjectHubList,ClassicSessionsList,MergedClassicList— inReact.memoso stable-prop drain ticks skip re-running the list for tree, hub, and classic alike.No behavior change:
React.memoonly skips a re-render when props are shallow-equal, and every list prop is a fresh ref fromuseMemo/state.Why it isn't the whole story
On-device tracing with a per-commit probe found the Hub still re-rendering continuously after this change, driven by two things this PR does not touch:
serverFetchStatusstore re-rendering subscribers on every HTTP response (serverFetchStatus store re-renders subscribers on every HTTP response (fresh object on unchanged status) #564).conversation_updatedWS frames re-draining the whole eager conversations query per frame (conversation_updated WS frames trigger a full eager-conversations re-drain per frame (sustained Hub re-render loop) #565).Both are fixed in #566, which is what actually stops the loop (render rate ~6/sec → ~0.65/sec on-device). This PR remains worthwhile because it bounds the per-page progress bursts that #566 does not address.
Verification
ESLint clean;
tscno new errors (the repo-widerouter.pushtyped-routes errors are pre-existing and unrelated).Unit:
useSession.test5/5 andServerRowRefreshing10/10 pass locally;useConversations.testleft to CI.