DEV-402: convert Array.includes/some to Set.has in render loops#1893
Merged
Conversation
Resolves O(n) lookups in three components by building a Set once and using Set.has() for O(1) membership tests inside loops and JSX renders. https://app.clickup.com/t/86af351da
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
🚅 Deployed to the anticapture-pr-1893 environment in anticapture-infra
14 services not affected by this PR
|
Collaborator
🎨 UI Review
No UI issues foundAll three changed files optimize in-render lookups from O(n) to O(1) with zero change to rendered output:
The Generated by Claude Code |
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
Array.includes()andArray.some()O(n) lookups withSet.has()O(1) lookups in three dashboard components.useMemorecomputation), eliminating repeated full-array scans inside loops.Approach
Each occurrence was handled according to its React context:
TokenDistributionDialog.tsxselectedMetrics.includes()andnotSupportedMetrics.includes()insidemetrics.map()useMemo-wrapped Sets, replace with.has()MultilineChartAttackProfitability.tsxfilterData?.includes()inside nestedsortedDates.map().forEach()filterDataSetonce before the outer map, replace with.has()SectionComposedChart.tsx.some()calls onappliedMetricsin JSXappliedMetricTypesandappliedMetricAxesSets beforereturn, replace with.has()Files changed and why
apps/dashboard/features/token-distribution/components/TokenDistributionDialog.tsx— twouseMemoSets replacingincludes()on state + config arrays iterated per renderapps/dashboard/features/attack-profitability/components/MultilineChartAttackProfitability.tsx—filterDataSetbuilt once inside the existinguseMemobefore the nested loopapps/dashboard/features/token-distribution/components/SectionComposedChart.tsx—appliedMetricTypes+appliedMetricAxesSets replacing three separate.some()scans on every renderAssumptions I made
chartConfig[key]?.typeandchartConfig[key]?.axisvalues are stable strings;undefinedentries in the Sets are harmless (.has("secondary")won't matchundefined).notSupportedMetricsis derived from staticdaoConfig, so itsuseMemodeps ([notSupportedMetrics]) will rarely invalidate.filterDatais already a dependency of thechartDatauseMemo, sofilterDataSetis correctly re-derived whenfilterDatachanges.What I did NOT do
useMemotoSectionComposedChartfor the Sets (component is small, no hooks infra; pre-returnplacement suffices —appliedMetricscomes in as a prop so the Set is recreated only when the prop changes anyway)..some()/.filter()/.find()calls in these files beyond the scope listed in the task.Open questions for review
SectionComposedCharthas nouseMemo— should the two new Sets be wrapped inuseMemo(() => ..., [appliedMetrics, chartConfig])for extra safety? Left simple per task scope.ClickUp task
https://app.clickup.com/t/86af351da
Generated by Claude Code