Skip to content

DEV-402: convert Array.includes/some to Set.has in render loops#1893

Merged
pikonha merged 6 commits into
devfrom
claude/clickup-86af351da
May 14, 2026
Merged

DEV-402: convert Array.includes/some to Set.has in render loops#1893
pikonha merged 6 commits into
devfrom
claude/clickup-86af351da

Conversation

@pikonha
Copy link
Copy Markdown
Member

@pikonha pikonha commented May 12, 2026

Summary

  • Replace Array.includes() and Array.some() O(n) lookups with Set.has() O(1) lookups in three dashboard components.
  • Sets are built once per render (or per useMemo recomputation), eliminating repeated full-array scans inside loops.

Approach

Each occurrence was handled according to its React context:

File Original Fix
TokenDistributionDialog.tsx selectedMetrics.includes() and notSupportedMetrics.includes() inside metrics.map() Two useMemo-wrapped Sets, replace with .has()
MultilineChartAttackProfitability.tsx filterData?.includes() inside nested sortedDates.map().forEach() Build filterDataSet once before the outer map, replace with .has()
SectionComposedChart.tsx Three separate .some() calls on appliedMetrics in JSX Build appliedMetricTypes and appliedMetricAxes Sets before return, replace with .has()

Files changed and why

  • apps/dashboard/features/token-distribution/components/TokenDistributionDialog.tsx — two useMemo Sets replacing includes() on state + config arrays iterated per render
  • apps/dashboard/features/attack-profitability/components/MultilineChartAttackProfitability.tsxfilterDataSet built once inside the existing useMemo before the nested loop
  • apps/dashboard/features/token-distribution/components/SectionComposedChart.tsxappliedMetricTypes + appliedMetricAxes Sets replacing three separate .some() scans on every render

Assumptions I made

  • chartConfig[key]?.type and chartConfig[key]?.axis values are stable strings; undefined entries in the Sets are harmless (.has("secondary") won't match undefined).
  • notSupportedMetrics is derived from static daoConfig, so its useMemo deps ([notSupportedMetrics]) will rarely invalidate.
  • filterData is already a dependency of the chartData useMemo, so filterDataSet is correctly re-derived when filterData changes.

What I did NOT do

  • Did not add useMemo to SectionComposedChart for the Sets (component is small, no hooks infra; pre-return placement suffices — appliedMetrics comes in as a prop so the Set is recreated only when the prop changes anyway).
  • Did not touch any other .some() / .filter() / .find() calls in these files beyond the scope listed in the task.
  • Did not modify CI, migrations, deps, or infra.

Open questions for review

  • SectionComposedChart has no useMemo — should the two new Sets be wrapped in useMemo(() => ..., [appliedMetrics, chartConfig]) for extra safety? Left simple per task scope.

ClickUp task

https://app.clickup.com/t/86af351da


Generated by Claude Code

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
@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
anticapture-storybook Ready Ready Preview, Comment May 13, 2026 10:10pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
anticapture Ignored Ignored Preview May 13, 2026 10:10pm

Request Review

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 12, 2026

🚅 Deployed to the anticapture-pr-1893 environment in anticapture-infra

Service Status Web Updated (UTC)
prometheus ❌ Build Failed (View Logs) Web May 14, 2026 at 12:05 am
compound-api ❌ Build Failed (View Logs) May 13, 2026 at 11:26 pm
compound-indexer-offchain ❌ Build Failed (View Logs) May 13, 2026 at 11:10 pm
api-gateway ✅ Success (View Logs) Web May 13, 2026 at 10:15 pm
gateful ✅ Success (View Logs) Web May 13, 2026 at 10:15 pm
uniswap-api ✅ Success (View Logs) May 13, 2026 at 10:12 pm
ens-relayer ✅ Success (View Logs) May 13, 2026 at 10:11 pm
loki ✅ Success (View Logs) Web May 13, 2026 at 10:11 pm
grafana ✅ Success (View Logs) Web May 13, 2026 at 10:11 pm
tempo ✅ Success (View Logs) May 13, 2026 at 10:10 pm
alertmanager ✅ Success (View Logs) Web May 13, 2026 at 10:10 pm
nouns-indexer ✅ Success (View Logs) May 13, 2026 at 10:10 pm
otelcol ✅ Success (View Logs) May 13, 2026 at 10:10 pm
anticapture-mcp-server ✅ Success (View Logs) Web May 13, 2026 at 10:10 pm
ens-api ✅ Success (View Logs) May 13, 2026 at 10:08 pm
uniswap-indexer-offchain ✅ Success (View Logs) May 13, 2026 at 10:08 pm
scroll-api ✅ Success (View Logs) May 13, 2026 at 10:07 pm
shutter-indexer ✅ Success (View Logs) May 13, 2026 at 10:07 pm
lil-nouns-indexer ✅ Success (View Logs) May 13, 2026 at 10:07 pm
address-enrichment ✅ Success (View Logs) May 13, 2026 at 10:07 pm
gitcoin-api ✅ Success (View Logs) May 13, 2026 at 10:07 pm
fluid-indexer ✅ Success (View Logs) May 13, 2026 at 10:07 pm
lil-nouns-api ✅ Success (View Logs) May 13, 2026 at 10:07 pm
erpc ✅ Success (View Logs) Web May 13, 2026 at 10:07 pm
aave-api ✅ Success (View Logs) May 13, 2026 at 10:07 pm
ens-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
obol-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
fluid-api ✅ Success (View Logs) May 13, 2026 at 10:06 pm
shutter-api ✅ Success (View Logs) May 13, 2026 at 10:06 pm
nouns-api ✅ Success (View Logs) May 13, 2026 at 10:06 pm
ens-indexer-offchain ✅ Success (View Logs) May 13, 2026 at 10:06 pm
compound-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
gitcoin-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
scroll-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
gitcoin-indexer-offchain ✅ Success (View Logs) May 13, 2026 at 10:06 pm
aave-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
obol-api ✅ Success (View Logs) May 13, 2026 at 10:06 pm
uniswap-indexer ✅ Success (View Logs) May 13, 2026 at 10:06 pm
nodeful ✅ Success (View Logs) May 12, 2026 at 8:49 pm
14 services not affected by this PR
  • RabbitMQ
  • RabbitMQ Web UI
  • tailscale-entrance
  • caddy-zero-trust
  • s3manager
  • consumer
  • hyperindex-erpc
  • hyperindex-database
  • hyperindex-sync
  • hyperindex-sync-database
  • hyperindex-hyperrpc-database
  • hyperindex-hyperrpc
  • logic-system
  • dispatcher

Copy link
Copy Markdown
Collaborator

🎨 UI Review

Automated review · Spec: DEV-402 · Preview: auth-gated
⚠️ Reviewed without a Figma reference — no matching design found in PR body or ClickUp.
ℹ️ This PR contains no visual/UI changes — all diffs are pure JS performance optimizations (Array → Set lookups).


No UI issues found

All three changed files optimize in-render lookups from O(n) to O(1) with zero change to rendered output:

File Change Visual impact
TokenDistributionDialog.tsx includes()Set.has() for selectedMetrics + notSupportedMetrics None
MultilineChartAttackProfitability.tsx filterData?.includes()filterDataSet?.has() None
SectionComposedChart.tsx Three .some() scans → appliedMetricTypes + appliedMetricAxes Sets None

The undefined entries that can appear in appliedMetricTypes/appliedMetricAxes (when chartConfig[key] is absent) are harmless — Set.has("BAR") correctly returns false when "BAR" was never added. ✓


Generated by Claude Code

@railway-app railway-app Bot temporarily deployed to anticapture-infra / anticapture-pr-1893 May 13, 2026 22:09 Destroyed
@pikonha pikonha merged commit e3e2f7a into dev May 14, 2026
47 of 50 checks passed
@pikonha pikonha deleted the claude/clickup-86af351da branch May 14, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants