perf: memoize dashboard derived state to eliminate redundant renders#8
Closed
perf: memoize dashboard derived state to eliminate redundant renders#8
Conversation
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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
All derived values on the dashboard were recomputed inline on every React render — including renders triggered by unrelated state changes like
loadingtoggling back tofalse.Wrapped every computed value in
useMemowith tight dependency arrays:filteredResultsresults,applyDateFilter,selectedRegionavgPing/avgPacketLoss/avgJitterfilteredResultsregionsresults(not filter state)chartDatafilteredResultsserverChartDatafilteredResultsFor 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.tsxVerification