0077. The web keeps keyed list moves in TypeScript; the Rust version is for native
- Status: Proposed
- Date: 2026-11-14
- Decided by: integrator (internal only)
- Planning item: WP13 (execution ladder: Rust runtime hot paths), D22, D23
Context
WP13 moves the runtime's hot paths into Rust (crates/runtime) "behind the same API", and asks for the web to use the Rust build, as WebAssembly, where it is faster. The candidates on the web were the style table and keyed list updates. The style table is resolved entirely at build time on the web (classes in CSS), so it has no runtime path to move. Keyed list updates do: when a list changes, the runtime decides which rows to move.
The keyed list used to move every row out of place one by one: moving the first row of 100 to the end moved the other 99. The fewest moves keep the longest run of rows whose earlier positions increase, found in O(n log n).
Decision
- The fewest-moves function exists twice:
crates/runtime/src/list_moves.rs(built to WebAssembly bycrates/runtime/src/web.rswith wasm-bindgen 0.2.130) andpackages/client/src/web/list-moves.ts. The keyed list now moves only the rows outside that run; moving one row of 100 moves one row. - The web runtime uses the TypeScript one.
pnpm benchtimes both, the WebAssembly one called as the runtime would call it (positions copied into anInt32Array, answers out of aUint8Array). Median microseconds per call, three runs ofpnpm bench --budgetson the shared 4-core build machine (re-measured in review, 2026-11-14): | Rows, change | TypeScript | Rust (WebAssembly) | | --- | --- | --- | | 100, first row to the end | 5.3 / 3.7 / 3.3 | 3.4 / 4.7 / 4.4 | | 100, one row inserted | 2.4 / 3.2 / 2.7 | 3.1 / 3.0 / 3.9 | | 100, shuffled | 1.9 / 4.2 / 2.3 | 3.7 / 4.6 / 4.0 | | 1,000, first row to the end | 33.0 / 27.6 / 34.9 | 29.0 / 23.1 / 30.8 | | 1,000, one row inserted | 34.2 / 27.9 / 34.8 | 29.0 / 23.1 / 36.2 | | 1,000, shuffled | 26.6 / 21.0 / 25.1 | 31.9 / 26.4 / 33.3 | | 10,000, first row to the end | 355 / 275 / 391 | 342 / 385 / 363 | | 10,000, one row inserted | 378 / 352 / 365 | 487 / 329 / 380 | | 10,000, shuffled | 594 / 523 / 698 | 283 / 299 / 365 | What the numbers say, without rounding them towards the choice: TypeScript is faster at 100 rows in eight of the nine pairs. At 1,000 rows the WebAssembly is faster when one row moves or is inserted (five of six pairs) and TypeScript is faster when the list is shuffled (three of three). At 10,000 rows the WebAssembly is clearly faster on a shuffle, 1.6 to 2.1 times, in all three runs here (and in one of the two earlier runs; the other had TypeScript ahead); one row moved or inserted is level. So the Rust build is faster for long lists that reorder, by about 0.3 ms per update at 10,000 rows. - The web keeps TypeScript anyway, for these reasons: the lists apps show are tens to hundreds of rows, where TypeScript is ahead; the WebAssembly is 23 KB that would have to load, asynchronously, before the first list update; and the gain where it wins is a fraction of a millisecond against the milliseconds the DOM moves themselves take for 10,000 rows. Using both, with the WebAssembly above some length, would be two code paths for that fraction.
- The Rust version stays as the native runtime's, where there is no JavaScript to call, and as the measured alternative: the benchmark runs in
pnpm bench, with budgets incrates/runtime/bench/budgets.json.
Alternatives considered
| Option | Why not |
|---|---|
| Use the WebAssembly for long lists | It is faster for a shuffle of 10,000 rows, but by about 0.3 ms, at the cost of two code paths and an asynchronous load before the first large list; at 1,000 rows neither is ahead on every change |
| Move the whole keyed list into WebAssembly | The DOM is only reachable from JavaScript; every move would cross the boundary |
| Keep the old one-by-one moves | Moving one row to the end moved all the others: more DOM work, and lost scroll and focus in some browsers |
Consequences
- If the native runtime's numbers or a later browser change the picture, the benchmark is already there to rerun; CI runs it with its budgets (
pnpm bench --budgets). - An app that reorders lists of thousands of rows would gain from the WebAssembly; if such apps appear, using it above a row count is the change to make, with this benchmark to set the count.