Optimize caching, polling, and retry strategies for performance#760
Merged
Conversation
Reduce origin (Cloud Run) request load that was driving the ~9x request spike: - Update-version checker (app layout): was fetching the full current page with `no-store` every 60s on every signed-in tab, forever. Now polls ~every 15 min, only while the tab is visible, with jitter so clients don't poll in lockstep, and stops once an update is detected. This was the single biggest driver of both the request spike and uncached CDN bandwidth. - Market page: the 60s refresh is a Server Action hitting the origin; throttled to 5 min (underlying market data revalidates on 60s+ anyway). - BTC price ticker: throttled from 60s to 5 min. - Wallet error-retry: replaced the fixed 3s retry with exponential backoff (3s/6s/12s, capped at 60s) and debounced the on-focus retry so a focus storm can't fire back-to-back origin calls. https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Address the Firebase App Hosting CDN cache-miss rate (uncached origin bandwidth jumped 52 GiB -> 726 GiB). App Hosting only edge-caches responses whose origin emits a cacheable Cache-Control header, and almost nothing did. next.config.ts headers(): - /public static assets (svg/png/jpg/webp/ico/woff/woff2): 1 week + SWR. - manifest.json: 1 day. - /landing and /about (public marketing pages): s-maxage 1h + SWR. - Signed-in app shells (dashboard, analysis, security, chat, report, coin-control): s-maxage 5m + SWR. These render an identical shell per user — wallet data loads client-side via Server Actions and auth gating is client-side — so only the static shell is cached; per-user data requests are separate POSTs that always reach the origin. Parameterised routes (address/[address] etc.) and /api/* are intentionally excluded. Also: - /landing and /about: add `revalidate = 3600` (ISR) to back the headers. - sitemap: use a stable lastModified instead of `new Date()` so it stops appearing "always new" to crawlers on every build. https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Code-review follow-up. In the version-update checker, if the `fetch(window.location.href)` is still in flight when the effect is cleaned up (component unmounted), the resolved callback could call `setIsUpdateAvailable` on an unmounted component. The cleanup already sets the shared `stopped` flag, so check it before the state update. https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Optimize caching, polling, and retry strategies for performance
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.
No description provided.