Repository navigation
Navigation costs: SvelteKit's link scan and page walks in the DOM layer - #13
Open
theetherGit wants to merge 5 commits into
Open
theetherGit wants to merge 5 commits into
theetherGit wants to merge 5 commits into
Conversation
A cycle collection, with the DROPs it queues applied. Put before a timed step, it keeps a collection from landing in one run and not the next: without it, the Tracker's Board visit varies from 78 to 117 ms headless; with it, from 80 to 87. The measurements for this branch use it, before and after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SvelteKit reads every link's `href` after each navigation, to set up preloading, and the getter built a whole URL each time to return its string. The resolved string is now kept, keyed by the attribute and the page's address, so a changed attribute or a navigation gives a fresh answer (tested both ways). Headless, the Tracker at 1,000 issues, a cycle collection before each step, medians of 7: | | before | after | |---|---:|---:| | `href`, per link on the Board | 4.9 µs | 0.47 µs | | SvelteKit's link loop, per link | 16.3 µs | 11.95 µs | | a repeat visit to the Board | 76 ms | 73 ms | | a first visit to the Board | 136 ms | 137 ms | A first visit gains nothing: the page's address is new, so every link misses. Repeat visits are where it pays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Walks of the page went through the general matcher for every element:
the parsed selector looked up, each alternative tried, a closure made per
element. SvelteKit walks the whole page twice after every navigation,
for `a` (its link scan; the tag index gives up above 64 elements) and
for `[autofocus]`. A selector's test is now built once: one tag, one
attribute that must be there, one id or one class gets a test of its
own, any other compound without combinators is matched directly, and the
rest as before. The tests check each against the general matcher.
Headless, the Tracker at 1,000 issues, a cycle collection before each
step, medians of 7:
| | before | after |
|---|---:|---:|
| `querySelectorAll('a')` on the Board (3,529 elements) | 1,775 µs | 800 µs |
| `querySelector('[autofocus]')` on the Board | 2,475 µs | 750 µs |
| a repeat visit to the Board | 73 ms | 70 ms |
| a first visit to the Board | 137 ms | 134 ms |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every `new URL` made a URLSearchParams and wrote two WeakMaps, the raw query and whether the URL has an authority, even when nothing would read them. Routers make URLs for their parts: SvelteKit one per link on the page after every navigation. `searchParams` is now made on first use, from the query as it is then, and the other two are private fields that `parse` reads through the class. `searchParams` is no longer an own property, as it is not in Node. Tested against Node's URL on 22 and 26, and for writes before and after the params are first read. Headless, the Tracker at 1,000 issues, a cycle collection before each step, medians: | | before | after | |---|---:|---:| | `new URL(href, base)`, per link on the Board | 4.27 µs | 0.87 µs | | SvelteKit's link loop, per link | 12.18 µs | 7.28 µs | | a repeat visit to the Board (2 rounds of 9) | 70 ms | 69 ms | Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compare/results/nav-cost.md, from make_nav_report.py: session nav-1, main against this branch at 1,000 issues (idle, opening an issue, switching screens), with SvelteKit's link scan piece by piece before and after, and what a first visit costs. HANDOVER: the job, the growth cost a first visit pays (the next job) and what is left. CHANGELOG: navigation is faster, and `searchParams` is no longer an own property of a URL. README: what navigation costs. CLAUDE.md: `drive`'s `gc:` for timing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Navigation in SvelteKit apps gets cheaper in the DOM layer.
Headline (Tracker, 1,000 issues, session
nav-1, main against this branch, interleaved, 1 warm-up and 3 runs, Stage Manager off): the turn that renders the Board is 5.5 ms shorter, and Issues' 3.2 ms. SvelteKit's look at each link after a navigation goes from 16.3 to 7.3 µs a link.The full report is
compare/results/nav-cost.md, generated bymake_nav_report.py.What it does
After every navigation SvelteKit walks the whole page twice. One walk is for
a, to set up link preloading. For each link it readshref, makes anew URLof it, and callsgetAttributefive times on every ancestor up to<html>. The other walk is for[autofocus]. Each change below is its own commit:b887ad3drivegets agc:step: a cycle collection before a timed step, so the before and after numbers use the same tooldc3c802hrefis resolved once per attribute value and page address64706eaquerySelectorAll('a')on the Board 1,775 µs,[autofocus]2,475 µs6fec75aurl.js:searchParamsis made on first use; the raw query and the no-authority flag are private fieldsnew URL(href, base)4.27 µsBoard repeat visit, headless, with a collection forced before each step: 76 → 73 → 70 → 69 ms across the three fixes.
One behaviour change:
searchParamsis no longer an own property of a URL. That matches browsers and Node, and it's in the CHANGELOG.In a window
Insights' mark is 7.6 ms later on the branch, while its render turn is the same. The difference is in where the click lands in the frame. SvelteKit follows a link from a
requestAnimationFramecallback, which waits for the next vsync. While the nav item's hover transition draws, frames come every 13 ms, so a mark can move by up to a frame depending on where the click falls in that cycle. Headless, with no frames, Insights' first visit is 1 ms quicker.Found on the way, not changed here
cn(), Svelte's templates, Bits UI, the app's data, or QuickJS's collector. That's the next job.preload-fix.md, with the scan removed) was the[autofocus]walk.Tests
dom.test.js:hrefcache follows a changed attribute and a navigation:not(:not(…))url.test.js:searchParamsmade after a write tosearchorhref, and writes after itpnpm test(151 QuickJS host tests) and the V8 host tests (145) pass locally.🤖 Generated with Claude Code