Skip to content

Memoize OverviewTab aggregation (extract pure overviewStats + useMemo)#5

Merged
cybermejo merged 1 commit into
worktree-studio-modularize-and-testfrom
worktree-studio-overview-memo
Jun 17, 2026
Merged

Memoize OverviewTab aggregation (extract pure overviewStats + useMemo)#5
cybermejo merged 1 commit into
worktree-studio-modularize-and-testfrom
worktree-studio-overview-memo

Conversation

@cybermejo

Copy link
Copy Markdown
Owner

Summary

Memoizes the Overview tab's aggregation so it isn't recomputed on every render.

Stacked on #2 (base worktree-studio-modularize-and-test) — OverviewTab is introduced by #2. GitHub will retarget this to main once #2 merges.

Why

OverviewTab computed its full aggregation (sentiment distribution, tone counts, engagement totals, averages, top-5 performers) inline in the function body — unlike BrandsTab/CaptionStudio, which useMemo. Any parent re-render redid the whole O(n) sweep over all tweets.

What changed

  • Extracted the aggregation verbatim into a pure overviewStats(tweets) in src/lib/stats.js.
  • OverviewTab calls it via useMemo(() => overviewStats(tweets), [tweets]). The JSX is unchanged.
  • Bonus: the dashboard aggregation is now unit-testable without a DOM (no jsdom/Testing Library needed).

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.

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 cybermejo self-assigned this Jun 17, 2026
@cybermejo cybermejo added the enhancement New feature or request label Jun 17, 2026
@cybermejo
cybermejo merged commit 7f7ad6d into worktree-studio-modularize-and-test Jun 17, 2026
4 checks passed
@cybermejo
cybermejo deleted the worktree-studio-overview-memo branch June 17, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant