Skip to content

perf: memoize dashboard derived state to eliminate redundant renders#8

Closed
bokiko wants to merge 1 commit intomainfrom
auto/improve-2026-03-19-perf
Closed

perf: memoize dashboard derived state to eliminate redundant renders#8
bokiko wants to merge 1 commit intomainfrom
auto/improve-2026-03-19-perf

Conversation

@bokiko
Copy link
Owner

@bokiko bokiko commented Mar 19, 2026

Summary

All derived values on the dashboard were recomputed inline on every React render — including renders triggered by unrelated state changes like loading toggling back to false.

Wrapped every computed value in useMemo with tight dependency arrays:

Value Deps
filteredResults results, applyDateFilter, selectedRegion
avgPing / avgPacketLoss / avgJitter filteredResults
regions results (not filter state)
chartData filteredResults
serverChartData filteredResults

For a 100-result set this eliminates 5 O(n) reduce passes + 2 groupBy passes per extraneous render. At 500-1000 results (natural growth) the savings become measurable. The change also makes data flow explicit — easy to see which derived values depend on which inputs.

Files changed

  • web/src/app/dashboard/page.tsx

Verification

  • Build: clean
  • Lint: no new errors (existing img warnings in page.tsx pre-date this PR)

All derived values on the dashboard (filteredResults, avgPing,
avgPacketLoss, avgJitter, regions, chartData, serverChartData) were
recomputed inline on every React render — including renders triggered
by unrelated state updates like loading toggling back to false.

Each computation is now wrapped in useMemo with the tightest possible
dependency array:

- filteredResults: depends on results, applyDateFilter, selectedRegion
- avgPing / avgPacketLoss / avgJitter: depend on filteredResults only
- regions: depends on results only (not filter state)
- chartData: depends on filteredResults
- serverChartData: depends on filteredResults

For a typical result set (~100 items) this eliminates 5 O(n) reduce
passes and 2 groupBy passes on every render that doesn't change the
underlying data. At 100 results the savings are modest; at the 500–1000
result scale the dashboard would hit without this change the difference
is measurable. Memoization also makes the data flow explicit — it's now
clear at a glance which data depends on which filters.
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@bokiko bokiko closed this in 8054623 Mar 20, 2026
@bokiko bokiko deleted the auto/improve-2026-03-19-perf branch March 21, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant