Skip to content

Memoize the Analytics period data selection and derived KPIs to cut chart re-renders #499

Description

@1nonlypiece

📌 Description

src/pages/Analytics.tsx recomputes the selected-period dataset and derived
metrics on every render, and the chart token sync via MutationObserver can
trigger extra renders. This issue memoizes the period selection and derived KPI
values so the recharts subtree only re-renders when inputs actually change.

🎯 Requirements and Context

  • Wrap period-data selection and KPI derivations in useMemo keyed on period and
    tokens.
  • Stabilize callback identities passed to chart children with useCallback.
  • No change to displayed values; verify with render-count assertions.

🛠️ Suggested Execution

1. Fork the repo and create a branch

git checkout -b perf/analytics-memo

2. Implement changes

  • Update src/pages/Analytics.tsx.
  • Tests: extend src/pages/__tests__/Analytics.test.tsx asserting stable output
    and reduced re-computation.
  • Docs: extend docs/PERFORMANCE.md.

3. Test and commit

  • Run npm test.
  • Cover edge cases: period switch recomputes once, theme change recomputes
    tokens only, identical inputs skip recompute.

Example commit message

perf: memoize Analytics period selection and derived KPIs

✅ Guidelines

  • Minimum 95% test coverage on the new/changed lines.
  • No change to displayed metrics.
  • Timeframe: 96 hours.

🏷️ Labels

type-performance · area-frontend · MAYBE REWARDED · GRANTFOX OSS · OFFICIAL CAMPAIGN

💬 Community & Support

  • Join the Disciplr contributor Discord to coordinate, ask questions, and get
    unblocked fast: https://discord.gg/xvNAvMJf
  • Please introduce yourself in the channel before you start so we can avoid
    duplicate work, pair you with a reviewer, and get your PR merged quickly.
  • Maintainers actively triage this channel and aim for fast, clear, respectful
    reviews — reach out any time you're blocked.

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions