perf: improve LCP by parallelising board load and caching decrypts#216
Merged
Conversation
The card body was the dominant LCP element. Three changes shorten the critical path to its first paint: - Board.svelte onMount now starts getRanks and the three firestore subscription handshakes in parallel instead of serialising them, and drops the 200ms fade-in on the cards container. busy=false now flips as soon as ranks REST + the password check resolve, rather than waiting for every subscription to register. - firestore.signIn() is memoised so the parallel subscribers share a single /auth + signInWithCustomToken round-trip. - encryption.decrypt() caches results (LRU, bounded at 1024 entries) so re-renders of the same ciphertext don't re-run PBKDF2's 200k iterations.
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.
Summary
The Core Web Vitals report flags the card body (
div.p-1.w-100.pre-wrapinCard.svelte) as the dominant LCP element. Three changes shorten the critical path to its first paint:Board.svelteonMount. Previously it serialised six awaits —getBoard→getRanks→checkPassword→ threesubscribeToXcalls (each with its ownsignInround-trip) — before flippingbusy = false. NowgetRanksand the three firestore subscription handshakes run concurrently, andbusy = falseflips as soon as ranks REST + password check resolve. Subscriptions complete in the background; cards/ranks populate as their first snapshots arrive.transition:fadeon the cards container. Pure win — that 200ms was being added on top of the LCP every load.signIn()infirestore.jsso the three concurrent subscribers share one/auth+signInWithCustomTokenround-trip instead of racing three.decrypt()results inencryption.js(LRU, bounded at 1024 entries) so re-renders of the same ciphertext don't redo PBKDF2's 200k iterations. Helps encrypted boards on every reactive update after the first paint.Two further ideas from the analysis were deferred as too invasive for this PR: pre-decrypting cards eagerly into the store, and moving PBKDF2 off the main thread via Web Workers.
Test plan
npm run lintnpm run buildnpx cypress run— full local suite (86 tests across 19 specs) passes, includingEncryption.cy.js,ConnectionLost.cy.js,OwnerRealtimeSync.cy.js,OpenPermission.cy.jshttps://claude.ai/code/session_01CbPv23BpW2H57tvRh7fxqQ
Generated by Claude Code