Memoize OverviewTab aggregation (extract pure overviewStats + useMemo)#5
Merged
cybermejo merged 1 commit intoJun 17, 2026
Conversation
OverviewTab recomputed its full aggregation (sentiment distribution, tone counts, totals, averages, top-5) inline on every render, unlike the other tabs which useMemo. On large datasets any parent re-render redid the whole O(n) sweep. Extract the aggregation verbatim into a pure overviewStats(tweets) in lib/stats.js and call it via useMemo([tweets]) in the component. The JSX is unchanged. As a bonus the dashboard aggregation is now unit-testable without a DOM. Adds lib/stats.test.js (5 tests). Build green (identical CSS hash); 45 tests pass.
cybermejo
merged commit Jun 17, 2026
7f7ad6d
into
worktree-studio-modularize-and-test
4 checks passed
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.
Summary
Memoizes the Overview tab's aggregation so it isn't recomputed on every render.
Why
OverviewTabcomputed its full aggregation (sentiment distribution, tone counts, engagement totals, averages, top-5 performers) inline in the function body — unlikeBrandsTab/CaptionStudio, whichuseMemo. Any parent re-render redid the whole O(n) sweep over all tweets.What changed
overviewStats(tweets)insrc/lib/stats.js.OverviewTabcalls it viauseMemo(() => overviewStats(tweets), [tweets]). The JSX is unchanged.Testing
Adds
src/lib/stats.test.js(5 tests: empty input, sentiment counts, engagement sums + averages, tone sorting, top-5 ranking). Build green with an identical CSS hash (markup unchanged); 45 tests pass.