Repository navigation
perf: compress static assets and stop idle redraws - #36
Merged
Merged
Conversation
The test sampled the fake upstream's closedAt the instant the client saw the error, but the server's close reaches the upstream a moment later, so it failed about 1 run in 10 on Node 20 (3/30 before, 0/30 after). Co-authored-by: Claude Code <noreply@anthropic.com>
fetch() decodes compressed bodies, so perf-api reported the decoded size even for a compressing server. Move the measurement to a shared module that reads raw bytes over node:http, and add an offline 'perf-server.mjs --shell' that runs it against the harness server. Co-authored-by: Claude Code <noreply@anthropic.com>
The page, styles and code (1 KB or more) are compressed once per content hash and served with Vary: Accept-Encoding. Each encoding gets its own ETag so a cache never answers one encoding with another, and If-None-Match also accepts a CDN-weakened tag. Fonts and PNGs are sent as they are. Cache-Control and the ?v=/CACHE_NAME scheme are unchanged. App shell on the wire (perf-server.mjs --shell): 237.9 KB -> 157.6 KB; the 12 text files go from 112 KB to 30 KB. Closes #25 Co-authored-by: Claude Code <noreply@anthropic.com>
Checks in headless Chrome that the shell arrives compressed, that the service worker's cached copies decode to the real files, and that the app still opens offline. Co-authored-by: Claude Code <noreply@anthropic.com>
idle-cpu now also measures the app with reduced motion and with another screen shown, and echo-window samples how much of the mic line is drawn each second (null while it is hidden). Co-authored-by: Claude Code <noreply@anthropic.com>
Three animation loops ran all the time, about 180 frames a second while idle: the orb, the hidden mic line, and a loop that only fed the orb its level. Now the orb reads its level itself, draws about 20 frames a second when it only breathes (well under a pixel of movement per frame) and 10 with reduced motion, and stops while another screen is shown. The mic line is drawn only while it is visible. Paced frames keep real time, so the animation looks the same. Idle Talk screen (repro-browser idle-cpu, 2 runs each): rAF callbacks/s 166-181 -> 19; task ms/s 169-285 -> 60-67 other screen 178-181 -> 0 rAF/s; reduced motion 181 -> 10 rAF/s Cache version bumped to v12. Closes #22 Co-authored-by: Claude Code <noreply@anthropic.com>
Switching tabs mid-conversation left the mic line drawing at 60 frames a second off screen (repro-browser echo-window: 60.5 -> 0 rAF/s). The screen now counts toward whether it is shown. Also: both canvases read the live reduced-motion query instead of caching or re-querying it, the waveform gets its data source once, the orb starts with the Talk screen, and the frame-time cap is derived from the slowest pace. Co-authored-by: Claude Code <noreply@anthropic.com>
…m sw.js getRaw moves to test/harness/http.mjs (with a method, so the HEAD test uses it too), and the shell-weight probe takes the code modules from the service worker's APP_SHELL instead of a hand-kept copy. Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Claude Code <noreply@anthropic.com>
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.
What changed
Faster first load (#25). The server now sends text files (the page, styles and code, 1 KB or larger) compressed with brotli, or gzip for browsers without brotli. Each file is compressed once per version and kept in memory. Responses carry
Vary: Accept-Encoding, and each encoding gets its own ETag ("<hash>-br","<hash>-gzip","<hash>"), so a cache never gives a browser the wrong encoding. A 304 revalidation still works, including when a CDN has weakened the ETag. Fonts and PNGs are sent as they are.Cache-Control,?v=NandCACHE_NAMEwork as before.Less battery drain while idle (#22). Three animation loops ran all the time, about 180 redraws a second with nothing happening:
Now:
Frames drawn at the slower pace still follow real time, so the animation runs at the same speed. Cache version bumped v11 → v12.
Flaky test. '#13 an upstream that never completes setup…' checked that the upstream was closed at the exact moment the client saw the error. The server's close reaches the fake upstream a moment later, so the test sometimes failed. It now waits for the close with the shared
waitFor.Also:
perf-apimeasured the shell withfetch, which decodes compressed bodies, so it could never have shown compression. The measurement now counts raw bytes;node scripts/perf-server.mjs --shellruns it offline.sw-offline.idle-cpunow also measures reduced motion and another screen shown.echo-windownow records whether the mic line is drawn each second, and whether anything draws when you switch screens mid-conversation.Closes #22
Closes #25
Evidence
Flaky test, run 30 times alone on
/usr/bin/node20:Bytes on the wire for the app shell (
perf-server.mjs --shell, 18 assets):The 12 text files go from about 112 KB to about 30 KB, e.g.
app.js31,114 → 8,228 bytes andstyles.css25,570 → 5,122 bytes. Fonts and icons are unchanged.Service worker (
repro-browser sw-offline, headless Chrome):parley-v12cache holds 22 entries, and the cachedapp.jsis identical to the file;Idle cost (
repro-browser idle-cpu, two runs each; these numbers are noisy):During a conversation (
echo-window):double-tapstill sees one mic pipeline at 30–32 frames/s.Test suites:
npm run typecheck,npm testand/usr/bin/node --import tsx --test test/*.test.jsall pass. Test count went from 177 to 192: 8 compression tests (unit tests plus the real server) and 7 orb pacing tests. The onlytodoleft is the deliberate ACCESS_TOKENS one.Not done
delaybefore checking that the upstream closed (the timing assumption behind the flaky test). Neither has been seen to flake, so I left them alone.🤖 Generated with Claude Code