Skip to content

fix: downsample YieldBreakdownChart and memoize chart components for long ranges - #1096

Closed
Junirezz wants to merge 1 commit into
mainfrom
fix/1041-yield-breakdown-chart-downsampling
Closed

fix: downsample YieldBreakdownChart and memoize chart components for long ranges#1096
Junirezz wants to merge 1 commit into
mainfrom
fix/1041-yield-breakdown-chart-downsampling

Conversation

@Junirezz

Copy link
Copy Markdown
Owner

Summary

Closes #1041.

Heads up for reviewers: #1041's title is an exact duplicate of #982, which was already resolved by #1027 — that PR added sampleChartSeries() downsampling to APYTrendChart and VaultPerformanceChart. This PR does not re-do that work. It closes the one real gap left over and adds a related, narrow perf win:

  • YieldBreakdownChart never got the downsampling treatment the other two charts got. It's still capped at 90 mock days today so this isn't user-visible yet, but it was the one chart that would silently render every raw point once its data source grows past the shared 120-point render cap (e.g. once it's wired to a real multi-year history like the other charts). Brought it in line: sampleChartSeries() before render, animation disabled on downsampled series (matching the other two), and the displayed period total is computed from the full (undownsampled) data so it stays accurate regardless of render-side sampling.
  • Wrapped all three chart components in React.memo. None of their props change identity across unrelated parent re-renders (APYTrendChart's default data is a stable module constant, VaultPerformanceChart takes no props at all, YieldBreakdownChart's only prop is a primitive number), so this is a safe, low-risk change that avoids repeat Recharts SVG re-renders whenever something unrelated elsewhere in the tree re-renders (TVL ticker, balance polling, etc.) — this matters most for the largest, longest-range series.

Test plan

  • npx vitest run on the touched files (YieldBreakdownChart, APYTrendChart, chartSeries) — 16/16 passed
  • Added YieldBreakdownChart.test.tsx (none existed before)
  • npx tsc -b — no new type errors (one pre-existing, unrelated ToastCenter.tsx error present on main before this change too)
  • Maintainer to confirm no visual regression in the Yield Earnings chart on /portfolio

🤖 Generated with Claude Code

…long ranges

APYTrendChart and VaultPerformanceChart already downsample their series via
sampleChartSeries() before handing data to Recharts, but YieldBreakdownChart
never got the same treatment, so an "ALL" range on a long-lived vault would
render every raw point instead of the shared 120-point cap. Bring it in line
with the other two charts, disabling animation on downsampled series the same
way, and keep the displayed period total computed from the full (undownsampled)
data so it stays accurate.

Also wrap all three chart components in React.memo, since none of their props
change identity across unrelated parent re-renders (APYTrendChart's default
data is a stable module constant, VaultPerformanceChart takes no props, and
YieldBreakdownChart's only prop is a primitive number) — this avoids repeat
Recharts SVG re-renders on every unrelated poll/tick elsewhere in the tree,
which matters most for the largest, longest-range series.

Related to #1041, which duplicates #982 (already resolved by #1027 for the
other two charts).
@esthertitilayo-dev

Copy link
Copy Markdown
Contributor

Closing — this was opened under the wrong GitHub account (repo owner's, not the assigned contributor's) due to a tooling mistake on my end. Re-opening correctly from a fork under the right account.

@Junirezz Junirezz closed this Jul 29, 2026
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.

Frontend: Improve chart rendering performance for long time ranges

2 participants