Skip to content

perf(web): memoize current week hours and fix forecast cache invalidation - #35

Merged
K-Laron merged 1 commit into
mainfrom
perf/store-cache-correctness
Oct 17, 2026
Merged

K-Laron merged 1 commit into
mainfrom
perf/store-cache-correctness

Conversation

@K-Laron

@K-Laron K-Laron commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Problem

  1. getCompletionForecast in src/store.js relies on this.state.holidays for its workday exclusion simulation, but omitted this.getResourceVersion('holidays') from forecastCacheKey. When holidays were created, edited, or synced, the forecast cache served stale projections until entries or config changed.
  2. getCurrentWeekHours was computed repeatedly on dashboard renders without memoization, filtering and parsing dates across all entries every time.
  3. In src/pages/reports.js: renderSummaryPack, store.getAllEntriesWithDerivedStatus() was cloned and re-sorted ascending just to extract the earliest and latest date bounds. Since getAllEntriesWithDerivedStatus() is already sorted descending, sorting was completely redundant.

Mechanism

  1. Add this.getResourceVersion('holidays') to forecastCacheKey in src/store.js.
  2. Add version-keyed memoization for getCurrentWeekHours(now = new Date()) keyed by ${entriesVersion}:${mondayStr} so it caches across renders while automatically invalidating on entry modifications or weekly midnight rollover.
  3. In reports.js: renderSummaryPack, extract date bounds directly via entries[entries.length - 1]?.date (dateFrom) and entries[0]?.date (dateTo), eliminating array cloning and O(N log N) sorting.
  4. Added tests verifying holiday invalidation and memoization behavior in src/store-forecast.test.js.

Upstream Inspiration

  • pingdotgg/t3code#10118: "perf(web): skip checkpoint map rebuilds while streaming" (reuse stable caches across frequent getter invocations).
  • pingdotgg/t3code#20860: "perf(web): the open thread's chat chrome no longer re-renders on every streaming tick".
  • pingdotgg/t3code#17123: "perf(web): avoid re-highlighting active blocks when tokens do not change".

Before / After Numbers

  • npm test: 126/126 tests passing (5-run median: 570.23 ms).
  • npm run build: Vite build passes in ~1.84s.
  • renderSummaryPack: O(1) date bounds extraction instead of O(N log N) re-sort and clone.
  • getCurrentWeekHours: O(1) cached lookup during dashboard renders.
  • Correctness: Holiday updates immediately reflect in forecast calculations.

Risk

Very Low. Cache keys explicitly track resource versions and midnight calendar week transitions.

…tion

Inspired by pingdotgg/t3code#10118, pingdotgg/t3code#20860, pingdotgg/t3code#17123.
- Invalidate getCompletionForecast cache on holiday updates by including holidays version in key
- Memoize getCurrentWeekHours keyed by entries version and Monday date string
- Eliminate redundant array copy and sort in reports summary pack by indexing known sorted bounds
Copilot AI balanced review requested due to automatic review settings October 17, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41b8108e-c49f-4510-8131-a14883fc7f9f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@K-Laron
K-Laron merged commit 91dbb0a into main Oct 17, 2026
5 checks passed
@K-Laron
K-Laron deleted the perf/store-cache-correctness branch October 17, 2026 23:12
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.

2 participants