Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ What changes for apps:
- **`calyx --bundle` compiles again** inside the bundle, with the binary
it bundles.

### Navigation in SvelteKit apps is faster

After every navigation SvelteKit walks the page for its links, to set up
preloading, and for `[autofocus]`. The DOM layer now resolves a link's
`href` once per attribute and page, builds a selector's test once instead
of matching it from scratch on every element, and makes a `URL`'s
`searchParams` only when it is asked for. SvelteKit's look at each link
went from 16.3 to 7.3 µs; in the Tracker the turn that renders the Board
is 5.5 ms shorter and Issues' 3.2 (`compare/results/nav-cost.md`).

- `searchParams` on the DOM layer's `URL` is no longer an own property of
each URL, as in browsers and Node: `Object.keys(url)` no longer lists it.

## 0.2.0-alpha.0 (25 Nov 2026)

### Breaking: SvelteKit is the only router
Expand Down
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ at the size when a change adds crates or features.
AppKit: it cannot show a problem in how macOS delivers events.
`key <name>` (`key Escape`) and `type <text>` press keys; those start one
step later, at the document, because winit cannot build a key event.
- Timing a step headless, put `drive`'s `gc:` before it: a cycle
collection, so that none lands in one run and not the next (a Board visit
varies from 78 to 117 ms without it). Time with `Date.now()` in an
`eval:`: `performance.now()` stands still headless.
- `drive`'s `time:` moves virtual time and returns at once, so a `fetch`
over the network is still on its way. `real:SECONDS` lets real time pass
while the host's answers come in: `drive <app> real:4 text:SEL`.
Expand Down
54 changes: 47 additions & 7 deletions HANDOVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,50 @@ standing rules and `README.md` the architecture; this file is the work.
what was published before the rename, and under which names, is in
`CHANGELOG.md`.

## Navigation costs (27 Nov 2026, branch `nav-cost`)

After every navigation SvelteKit walks the whole page twice: `a`, to set
up link preloading (each link's `href`, a `new URL` of it, five
`getAttribute`s on every ancestor), and `[autofocus]`. Three changes in
the DOM layer, each its own commit:

- A link's `href` is resolved once per attribute value and page address
(`resolve_href` in `dom.js`): 4.9 to 0.47 µs a link.
- A selector's test is built once (`test_for` in `dom.js`): one tag, one
attribute that must be there, one id or one class gets a test of its
own, any other compound is matched directly. `querySelectorAll('a')` on
the Board went from 1,775 to 800 µs, `[autofocus]` from 2,475 to 750.
- `url.js`: `searchParams` is made on first use, and the raw query and the
no-authority flag are private fields: `new URL` from 4.27 to 0.87 µs.
`searchParams` is no longer an own property, as in Node.

SvelteKit's loop went from 16.3 to 7.28 µs a link. In a window (session
`nav-1`, `compare/results/nav-cost.md`) the Board's render turn is 5.5 ms
shorter and Issues' 3.2. Insights' mark is 7.6 ms later with the same
render turn: the click's `requestAnimationFrame` waits for the next vsync,
and where the click lands in a 13 ms frame moves the mark. `drive` has a
`gc:` step for timing headless: without it, a Board visit varied from 78 to
117 ms, with it from 80 to 87.

Found on the way, and not changed:

- **A first visit pays for growth.** The Board's first visit costs ~50 ms
over a repeat, on the old main too, spread evenly over its 300 cards.
Making and dropping 20,000 of the renderer's nodes beforehand takes all of
it away; plain objects, `Map`s or `WeakRef`s alone take 4-16 ms of it.
Not `cn()`, Svelte's templates, Bits UI, the data, QuickJS's collector or
its warm-up. Which part of the growth costs is the next job; startup's
first screen probably pays the same.
- The split build's first visits trail a single bundle by 1-1.5 ms, and
not on the Board: no turn waits for a route's stylesheet, and the chunk
is read in the turn that renders it.
- With the growth taken out of both, the Board's first visit is ~14 ms
behind the old main, ~9 of it the two walks before these changes; ~5 ms
is not accounted for.
- The ancestor walk (4.1 µs a link) is SvelteKit's own calls.
- The parsed-selector cache and the new test cache are unbounded: an app
that builds selectors with ids in them grows both.

## Modules load as QuickJS bytecode (26 Nov 2026, branch `bytecode`)

`calyx --compile <dist>` compiles every module of the app folder with the
Expand Down Expand Up @@ -87,13 +131,9 @@ Left for later, each its own job:
and **the server build** (the backend thread), which the adapter
refuses today.
2. **The host's size on Linux**, under the 30 MB budget.
3. **SvelteKit's link scan.** After every navigation SvelteKit looks at
each `<a>` on the page (its URL, its `data-sveltekit-*` options up the
ancestors) to set up preloading: about 32 µs a link in the DOM layer,
10 ms on the Board's 316. Main never paid it, because its `<html>` was a
stand-in with no children. `href`, attribute reads and `closest` are
where it can come down (`preload-fix.md`). Without it the Board is still
4.7 ms behind main on a repeat visit: not looked into.
3. ~~**SvelteKit's link scan**~~: done, branch `nav-cost` (above): 16.3 to
7.3 µs a link. The 4.7 ms the Board was still behind main without it
was the `[autofocus]` walk.
4. ~~**Blitz hit testing clipped to `overflow: hidden`**~~: done, blitz-dom
patch 14, for every box that clips its overflow (a scroll box too: the
counter's buttons stopped taking clicks once its list was scrolled).
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,10 @@ What the time is spent on, from sampling:
renderer's glyph atlas is now on (a patch to the vendored
`anyrender_vello_hybrid`), which cut the time spent painting by half. A
page with an endless animation, such as a `Skeleton`, still never idles.
- **Navigation.** After every navigation SvelteKit looks at each link on
the page, to set up preloading, and walks the page for `[autofocus]`: on
the Tracker's Board, 316 links of 3,500 elements, that is about 4 ms in the
DOM layer (7.3 µs a link and two walks of under 1 ms).
- **Start-up.** Modules load as bytecode, compiled when the app is built:
the Tracker's page starts 19-20 ms sooner than when QuickJS parsed and
compiled its 36 modules at every launch (`compare/results/bytecode.md`).
Expand Down
203 changes: 203 additions & 0 deletions compare/results/make_nav_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
"""Navigation after the DOM layer's three fixes, against main, at 1,000 issues.

python3 compare/results/make_nav_report.py [session] > compare/results/nav-cost.md

One interleaved session (default nav-1), Stage Manager off, warm-up and aborted runs left out:
main Sepal on main at 51d4598 build blitzb
branch Sepal on nav-cost at 6fec75a: the href cache, selector tests build blitzc
built once, url.js's lazy searchParams
Both bench builds were bundled by the same dist-profile host, built at
6fec75a (the branch changes no Rust the host runs): the two apps differ in
one chunk, the entry, which carries the DOM layer and url.js. Each cell is
the median of the runs, with the range under it.
"""
import json
import re
import statistics as st
import sys
from pathlib import Path

RESULTS = Path(__file__).parent
SESSION = sys.argv[1] if len(sys.argv) > 1 else 'nav-1'
COLS = [('main', 'blitzb'), ('branch', 'blitzc')]
HELP = ('WebKit', 'com.apple.WebKit')
MB = 1024 * 1024

RUNS = [json.loads(line) for line in (RESULTS / 'raw' / SESSION / 'runs.jsonl').open()]


def runs(build, n):
return [r for r in RUNS if r['status'] == 'ok' and not r.get('warmup') and r['build'] == build and r['scenario'] == n]


def median(vals):
vals = [v for v in vals if v is not None]
return st.median(vals) if vals else None


def cell(vals, d):
vals = [v for v in vals if v is not None]
if not vals:
return 'n/a'
f = lambda v: f'{v:,.{d}f}'
lo, hi = min(vals), max(vals)
return f'{f(st.median(vals))}<br><sub>{f(lo)}–{f(hi)}</sub>' if len(vals) > 1 and lo != hi else f(st.median(vals))


def table(title, scenarios, rows):
print(f'### {title}\n')
print('| | ' + ' | '.join(c for c, _ in COLS) + ' | branch − main |')
print('|---|' + '---:|' * (len(COLS) + 1))
for label, fn, d in rows:
vals = [[fn(r) for n in scenarios for r in runs(b, n)] for _, b in COLS]
a, b = median(vals[0]), median(vals[1])
gap = f'{b - a:+,.{d}f}' if a is not None and b is not None else 'n/a'
print(f'| {label} | ' + ' | '.join(cell(v, d) for v in vals) + f' | {gap} |')
counts = ', '.join(f'{c}: {sum(len(runs(b, n)) for n in scenarios)}' for c, b in COLS)
print(f'\n<sub>Runs: {counts}.</sub>\n')


def step(label, key):
def get(r):
s = next((s for s in r['steps'] if s['label'] == label), None)
return s.get(key) if s else None
return get


def mark(name):
return lambda r: (r.get('startup') or {}).get(name, {}).get('ms_from_exec')


def startup(key):
return lambda r: (r.get('startup') or {}).get(key)


def first_input(r):
return ((r.get('startup') or {}).get('first_input') or {}).get('ms_from_exec')


def frame_after_mounted(r):
return ((r.get('startup') or {}).get('first_frame_after_mounted') or {}).get('ms_from_exec')


def page_started(r):
"""The host's own count: index.html parsed, its scripts run, settled."""
for line in (RESULTS / r['log']).read_text().splitlines():
m = re.search(r'the page started in ([\d.]+)ms', line)
if m:
return float(m.group(1))
return None


def turn(mark_name):
"""The navigation's turn in the window trace: the `poll took` line after its MARK."""
def get(r):
lines = (RESULTS / r['log']).read_text().splitlines()
i = next((k for k, l in enumerate(lines) if f'MARK {mark_name}' in l), None)
if i is None:
return None
m = next((re.search(r'poll took ([\d.]+)ms', l) for l in lines[i:] if 'poll took' in l), None)
return float(m.group(1)) if m else None
return get


def presented(r):
d = r.get('trace_damage')
return d['full'] + d['partial'] if d else None


ram = lambda fp: sum(p['footprint'] for p in fp['processes'] if p['name'] not in HELP) / MB if fp else None
cpu = lambda r: r['usage']['cpu_ns'] / 1e6
gpu = lambda r: r['gpu_ns'] / 1e6 if 'gpu_ns' in r else None
wake = lambda r: r['usage'].get('interrupt_wkups')

print(__doc__.split('\n\n')[0].strip('"'), '\n')
print(f'Session `{SESSION}`, interleaved, 1 warm-up and 3 runs per build and scenario, Stage Manager off, '
'no screen recording. M4 Pro, macOS 27.0.1, 5K display at 75 Hz. Times are from the input.\n')

table('Idle, 20 s (scenario 3)', [3], [
('CPU time, ms', cpu, 1),
('GPU time, ms', gpu, 2),
('frames presented', presented, 0),
('interrupt wake-ups', wake, 0),
('RAM 5 s after load, MB', lambda r: ram(r.get('footprint_mounted5')), 1),
('RAM at the end, MB', lambda r: ram(r.get('footprint')), 1),
])
table('Open an issue (scenario 5)', [5], [
('click row → mark, ms', step('click row', 'ms_to_mark'), 1),
('click row → frame, ms', step('click row', 'ms_to_frame'), 1),
('Escape → mark, ms', step('Escape', 'ms_to_mark'), 1),
('Escape → frame, ms', step('Escape', 'ms_to_frame'), 1),
])
SCREENS = ('board', 'insights', 'settings', 'issues')
table('Switch screens (scenario 10)', [10], [
*[(f'{to} → mark, ms', step(f'click nav-{to}', 'ms_to_mark'), 1) for to in SCREENS],
*[(f'{to} → frame, ms', step(f'click nav-{to}', 'ms_to_frame'), 1) for to in SCREENS],
*[(f'{to}: the turn that renders it, ms', turn(f'nav:/{to}'), 1) for to in SCREENS],
])


print('''### Notes

- **The render turns are the cleaner number.** The Board's is 5.5 ms
shorter and Issues' 3.2; Settings and Insights are within 1 ms. The
marks and frames add the wait before that turn: SvelteKit follows a
link from a `requestAnimationFrame` callback, which waits for the next
vsync, and while the nav item's hover transition draws, frames are
coming every 13 ms. Where the click lands in that cycle moves a mark by
up to a frame. Insights shows it: the same render turn on both builds,
and its mark 7.6 ms later on the branch. Headless, where there are no
frames, its first visit is 1 ms quicker.
- **Idle** is the same: no frames, 34 and 32 wake-ups in 20 s.

### Where SvelteKit's link scan went

After every navigation SvelteKit takes `querySelectorAll('a')` and, for
each link, its `href`, a `new URL` of it, and five `getAttribute`s on every
ancestor up to `<html>`, to set up preloading. Timed piece by piece on the
Board (316 links, 8.9 ancestors each, 3,529 elements), headless, µs a link:

| | before | after |
|---|---:|---:|
| `a.href` | 4.9 | 0.47 |
| `new URL(a.href, document.baseURI)` | 4.27 | 0.87 |
| the ancestor walk (`getAttribute` and `parentNode`) | 4.35 | 4.11 |
| the loop, whole | 16.3 | 7.28 |
| `querySelectorAll('a')`, per call | 1,775 | 800 |
| `querySelector('[autofocus]')`, per call | 2,475 | 750 |

One commit for each, with a cycle collection before each timed step
(`drive`'s `gc:`): the Board's repeat visit went from 76 to 73 ms with the
`href` cache, to 70 with the selector tests, and to 69 with url.js. The
ancestor walk is SvelteKit's own five calls a level, which no change on
this side makes fewer.

The 4.7 ms the Board trailed the old main by (`preload-fix.md`, without the
scan) was `[autofocus]`, the other walk of the whole page: with both
walks taken out, the Board's repeat visit was 72 ms, the old main's
(`bae68bb`) 72 ms.

### First visits

A screen's first visit is not slower in the split build for any reason of
its own: headless, the split build trails a single bundle by 1-1.5 ms on
Insights, Settings and opening an issue (the route's chunk read and Vite's
preload helper adding a `modulepreload` link), and not at all on the
Board. The route's chunk is read in the turn that renders it, no turn waits
for a stylesheet, and the turns are the same: the click's frame, then the
timer that navigates and renders.

The Board's first visit costs ~50 ms over a repeat (136 against 76 ms
here), on the old main too. It is spread evenly over the 300 cards it
draws (210-320 µs a card, against 130-145), and it is neither `cn()` (0.55
ms), nor Svelte's templates (a custom renderer gets new nodes every time),
nor Bits UI, the app's data, QuickJS's collector or its warm-up. Making and
dropping 20,000 of the renderer's nodes before the first visit takes all of
it away: the process makes nodes in numbers it has not before. Which part
of that growth costs, JavaScript's or the allocator's, is the next job.

| headless, ms | first visit | repeat | first, 20,000 nodes made first | repeat, same |
|---|---:|---:|---:|---:|
| before | 134-136 | 76-77 | 76-78 | 70-72 |
| after | 132-136 | 72-73 | 73 | 67-68 |
''')
Loading