Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4ee3c63
chore(quest): claim quest/m2/ts-byte-views/arguments.md
kixelated Oct 28, 2026
6a20d83
perf(ts): pass byte slices to translated functions as their parts
kixelated Oct 28, 2026
81808c5
test(ts): differential cases for byte slices passed as their parts
kixelated Oct 28, 2026
159cc27
docs(ts): measure byte slices passed as their parts
kixelated Oct 28, 2026
45e1cce
Merge origin/main
kixelated Oct 28, 2026
6e5d2b6
style(ts): format the harness's imports
kixelated Oct 28, 2026
5b0bec7
style(ts): undo a stray rustfmt of main's code
kixelated Oct 28, 2026
c6207c2
Merge origin/main into quest/m2/ts-byte-views/arguments
kixelated Oct 28, 2026
25970f9
chore(quest): fold byte slices passed as parts into returns
kixelated Oct 29, 2026
9703843
Merge origin/main into quest/m2/ts-byte-views/arguments
kixelated Oct 29, 2026
fe5dc9a
feat(ts): return a Result's byte slices in a module-level slot
kixelated Oct 29, 2026
89b1179
Merge remote-tracking branch 'origin/main' into iter-160
kixelated Oct 29, 2026
60159e6
test(ts): refresh snapshots after merging main
kixelated Oct 29, 2026
9f3e4ff
Merge origin/main into quest/m2/ts-byte-views/arguments
kixelated Oct 29, 2026
bef6702
Merge origin/main into quest/m2/ts-byte-views/arguments
kixelated Oct 29, 2026
3b9cc55
quest: record #160's deciding bench, inconclusive
kixelated Oct 29, 2026
a4b559a
quest: record why #160's 8-byte varints are slower, and what time/ an…
kixelated Oct 29, 2026
465ac86
quest: park #160 until the host is quiet, with its next steps
kixelated Oct 29, 2026
aa3fe79
quest: record #160's evening bench and rescale's deopts
kixelated Oct 30, 2026
85e071e
Merge origin/main
kixelated Oct 31, 2026
c1092d2
style(ts): format the merge's resolutions
kixelated Oct 31, 2026
23def0f
Merge origin/main
kixelated Oct 31, 2026
5e9e64f
chore(ts): regenerate snapshots after merging main
kixelated Oct 31, 2026
3d32949
Merge origin/main
kixelated Oct 31, 2026
eccd5c3
chore(ts): regenerate snapshots after merging main
kixelated Oct 31, 2026
13f264c
perf(ts): return a slotted function's first Ok part, and its error in…
kixelated Oct 31, 2026
0700f72
chore(ts): regenerate the lang fixture's slots
kixelated Oct 31, 2026
6a07b19
perf(ts): return only a number as a slotted function's first part
kixelated Oct 31, 2026
1aea30e
fix(ts): keep the slot's error rule for returned numbers too
kixelated Oct 31, 2026
a30214d
perf(ts): read a slotted call's error before its other parts
kixelated Nov 1, 2026
30cb047
chore(ts): regenerate the lang fixture's slotted calls
kixelated Nov 1, 2026
32355f1
style(ts): format the slot's declaration
kixelated Nov 1, 2026
ecbf13a
Merge remote-tracking branch 'origin/main' into pr160
kixelated Nov 1, 2026
166dcee
fix(ts): judge a slotted function's lowering in the crate's typing en…
kixelated Nov 1, 2026
4284e80
Merge remote-tracking branch 'origin/main' into pr160
kixelated Nov 1, 2026
6c614fb
perf(ts): take a byte slice whole where the callee would make it anyway
kixelated Nov 1, 2026
bfa1dbb
fix(ts): take apart a slotted call of no arguments, and a held residu…
kixelated Nov 1, 2026
aade0fc
quest land: merge tested base
Nov 1, 2026
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
5 changes: 2 additions & 3 deletions quest/m2/ts-byte-views/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kept them as `(data, start, length)` made Chrome's varint decode 2.3-2.9x and fr

Decided with the maintainer on 2026-10-27: scalar-replace values built of byte slices,
scalars, tuples, `Option`, `Result`, and `ControlFlow`, materializing an object only where
one escapes, in three pieces that each land and measure alone (the children below).
one escapes, in pieces that each land and measure alone (the children below).
The precedents are `stepped` iterators, `range_nexts`, and `place_opts`, which a general
pass could later absorb.

Expand All @@ -30,6 +30,5 @@ Public API: the translator's output for byte slices.

## Required

- [Byte slices passed as parts](/quest/m2/ts-byte-views/arguments.md) - a function takes a slice's parts as arguments
- [Byte slices returned](/quest/m2/ts-byte-views/returns.md) - a function returns a split's parts without an object
- [Byte slices passed and returned as parts](/quest/m2/ts-byte-views/returns.md) - a function takes a slice's parts and returns a split's parts without an object
- [Byte slices in fields](/quest/m2/ts-byte-views/fields.md) - a private slice field is three fields
22 changes: 0 additions & 22 deletions quest/m2/ts-byte-views/arguments.md

This file was deleted.

2 changes: 1 addition & 1 deletion quest/m2/ts-byte-views/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ three `#private` fields.

## Required

- [Byte slices returned](/quest/m2/ts-byte-views/returns.md) - the measurement this one builds on
- [Byte slices passed and returned as parts](/quest/m2/ts-byte-views/returns.md) - the measurement this one builds on
97 changes: 72 additions & 25 deletions quest/m2/ts-byte-views/returns.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,81 @@
# [M] Byte slices returned
# [L] Byte slices passed and returned as parts

## Goal

A translated function that returns a value built of byte slices and scalars, such as
`Result<(&[u8], T), E>`, hands its parts to the caller without an object, and Chrome's
varint and frame decode on `just ts bench` are faster than with slices passed as parts
alone, with every differential test passing.
A translated function outside the API boundary takes each byte slice parameter as its parts
(`data`, `start`, `length`), and one that returns a `Result` of byte slices and scalars, such
as `Result<(u64, &[u8]), E>`, returns the error or `undefined`, with its payload in a
module-level out slot. Chrome's varint and frame decode on `just ts bench` are faster than
`main`, no workload is meaningfully slower in any engine, and every differential test passes.

## Plan

The [epic's](/quest/m2/ts-byte-views/README.md) hand edit measured Chrome 1.84x on varint
decode and 1.65x on frames with locals and returns, against [#120](https://github.com/moq-dev/rust2/pull/120).
Decided with the maintainer on 2026-10-28: this absorbs passing slices as parts, which
[#160](https://github.com/moq-dev/rust2/pull/160) implemented. Alone, parts gain nothing in
Chrome, since V8 already removes a slice object that doesn't escape once it inlines, and
Node's varint decode is 11-15% slower. They land only with the return ABI ("e1").
[#138](https://github.com/moq-dev/rust2/pull/138)'s per-function scratch measured slower
than `main`: copying between scratches when one function returns another's result cost the
most. One out slot per payload type, which a forwarded result already fills, avoids that.

Decided with the maintainer on 2026-10-27, from
[#138](https://github.com/moq-dev/rust2/pull/138): remeasure after
[arguments as parts](/quest/m2/ts-byte-views/arguments.md). #138 built a per-function
scratch object (the function returns which variant it made and writes the parts into its
module-level scratch), and it measured slower than `main` in Chrome (varint quic/1B 12.0
to 15.2 ns, frames 3B-reads 152 to 208 ns). One shared scratch per return type, reading
only the branch taken, measured about even; module `let`s measured 0.93x. Its branch keeps
the code. Pick the ABI only if it beats arguments alone.

- Only functions outside the API boundary that are never used as a value: not roots, fn
pointers, or closures.
- The callee writes its scratch at the JS `return`, after its MIR drops ran, so a `Drop`
that re-enters cannot overwrite it; the caller reads it at once, and temporary folding
never delays that read.
- Only functions outside the API boundary: not roots or closures. A function used as a
value is wrapped in an arrow that rebuilds the `Result`.
- The callee writes its slot at the JS `return`, after its MIR drops ran; the caller reads
it at once, before any other call.
- Start the slot's number fields as `undefined`, not `0`. Such a field holds any value once
a small integer is written (V8's `--trace-generalization`), so a write of a number that is
no small integer, as an 8-byte varint is, boxes a new one into an old object. A field
that starts as `0` stays a double written in place, but a slot that held one such number
converts every small one read after: on Chrome, `p_0` starting at `0` took QUIC and
leading-ones 8-byte varints from 1.13x and 1.24x `main`'s time to 0.88x and 1.06x, and
frame decode from 0.83x and 0.67x to 0.90x and 0.76x (2026-10-29, interleaved, a busy
host). Starting the starts and lengths at `0` changed nothing.
- Measured by hand edits of the codec's translation against `main`, Chrome first (2026-10-28,
on a busy host, so confirm on a quiet one): with the slot's fields tagged, Chrome's varint
and frame decode were each about 1.25x faster and group decode 1.06x, Node 1.33x and
1.40x, Firefox 1.21x and 1.10x, Bun even and 1.12x. Leading-ones varints of 8 bytes
measured 0.84x, within that run's noise.
- Decided with the maintainer on 2026-10-28: the translator writes the slot ("e1e"), its
fields starting as `undefined`. Land only if Chrome's varint and frame decode both beat
`main` on a quiet host, with the A/A route under 5% at the median and the max.
- Std's functions keep returning their `Result` whole, as their callers take it apart
already. A slot sits beside the first function in source order that writes it, so its
place doesn't depend on the order translation reaches them. `?`'s `Err` assigns a
result held as its parts, so a function with early returns writes the slot at each.
- Measured from the translator's own output on 2026-10-29, four `just ts bench` runs against
`main` at ccd52a0e. Chrome took 0.79-0.81 of `main`'s time on varint decode and 0.79-0.81
on frame decode, and Node 0.68-0.78 and 0.71-0.72. No run's Chrome A/A came under 5% at the
max: 5.5%, 61%, 16%, and 5.1%, with medians of 0.6-2.0%. It doesn't land on those runs.
- Open: Chrome's `time/u64` conversions took 1.11-1.17x `main`'s time in all four runs, with
that workload's A/A within 4%, and `btree/` 1.08-1.28x in three of them. Swapping which
route is `translated` kept `main` faster, so it isn't the route's place in the run. Their
functions translate to the same text on both, and a harness of their own, running every
workload in a fixed or shuffled order, timed them within 3% of `main`. So the gap is in
how the bench drives them, not in their translation. Find which before landing.
- Leading-ones varints of 8 bytes took 1.06-1.24x `main`'s time: `read_leading_ones` is too
big to inline, so each call boxes its value into the slot (above), where `main` returned
a new array. Returning the `Ok`'s first number, rather than writing it to the slot, would
avoid both the box and the conversion: an ABI change for the maintainer to weigh.
- Measured again on 2026-10-29 evening, other agents held, against `main` at ccd52a0e. CI
jobs on the host's runners started during both deciding runs, and neither met the A/A
rule: Chrome's was 4.0% at the median and 28% at the max, then 0.9% and 7.0%. Chrome took
0.81x and 0.79x `main`'s time on varint decode, 1.01x and 0.81x on frame decode, 1.02x and
1.03x on group decode, 1.18x and 0.84x on `btree/`, and 1.08x on `time/` conversions in
both. Node took 0.68-0.74x on varint and 0.71x on frame decode.
- Timed alone, `time/` and `btree/` on the bench still put `time/u64` at 1.12-1.18x `main`,
with the A/A within 6%, so the other workloads don't cause it. `btree/` swung from
1.12-1.26x to 0.85-0.94x. One bench run under `--trace-turbo-inlining` showed this
branch's `rescale` deopting 1,892 times, from Turbofan code compiled on stack replacement
before the `put_u64` calls after its loop had run, where `main`'s deopted 28 times; but
under `--trace-deopt` alone it deopted 4 and 7 times, so that loop came from the tracing.
- `rescale`'s only change from `main` is its `take_u64` calls: `take_u64` takes its slice
as parts but makes it an `rt.ByteSlice` on entry, so each caller holding one splits it
for the callee to make it again. That breaks this file's rule that nothing is made more
often than before, but at 5 objects per 1024 conversions it can't be 8%. Not passing as
parts a parameter its body makes on entry needs each callee's analysis before its
callers are lowered. A hand edit of that (all outputs equal) deopted 0 and 1 times.
- Parked as a draft until the host is quiet, with its runners frozen. Then run the
deciding bench, judged on family geomeans, and time the `take_u64` hand edit beside
this branch, to see whether the call's shape is `time/`'s gap.

Public API: the translator's output for byte slices.

## Required

- [Byte slices passed as parts](/quest/m2/ts-byte-views/arguments.md) - the measured win, landed first
9 changes: 9 additions & 0 deletions ts/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

- A function the config's roots don't name takes each `&[u8]` or `&[u8; N]` parameter
whose object its body never makes as its `data`, `start`, and `length`:
`read(buf, form)` is `read(buf.data, buf.start, buf.length, form)`. A caller takes
which from the output. One that returns a `Result` of byte slices
and scalars returns its error or `undefined`, and leaves the `Ok`'s parts in a
module-level slot, such as `sliceOut`. If the `Ok`'s first part is a number, it returns
that, or `undefined` for an error, and leaves the rest, or the error as `err`, in the
slot, such as `readOut`. A root still takes an `rt.ByteSlice` and returns
the `Result`.
- `rt.btreeCollect` takes whether it sorts and the keys' `!ne` after the entries, and
`rt.btreeCollectKeys` the keys' `PartialOrd::lt` and `!ne`, as in
`rt.btreeCollect(m, entries, true, Key.eq$cmp_PartialEq)`; neither takes a test for keys
Expand Down
31 changes: 29 additions & 2 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,35 @@ they need.
often than before stays one. `just ts bench` measured the codec's varint decode at 0.49
times the objects' time in Chrome, 0.57 in Firefox, 0.64 in Node, and 0.56 in Bun at
the geometric mean, and frame decode at 0.61, 0.56, 0.70, and 0.61, with the A/A route
within 0.04 and encode no slower. A parameter, a return, and a field are still a
`ByteSlice` ([byte slices without objects](/quest/m2/ts-byte-views/README.md)).
within 0.04 and encode no slower. A field is still a `ByteSlice`, as is a return but
for the `Result`s below ([byte slices without objects](/quest/m2/ts-byte-views/README.md)).
- A function only translated code calls takes each `&[u8]` or `&[u8; N]` parameter as
three, its `data`, `start`, and `length`, which its body holds as that local's parts:
not a root, which the outside calls, a closure, or an `async fn`. One whose object the
body would make anyway, to borrow it, to pass it to a function taking it whole, or at
all, it takes whole: as parts, the callee would just make the object instead of the caller.
That made Chrome's `btree/` workloads 1.06x `main`'s time through a helper that
rebuilt the slice it was passed. What a body makes depends on what its callees take, so
the functions a call reaches settle together, recursion included, each dropping the
slices it would make until none does. The function as a value is an arrow that takes
the slice whole. `just ts bench` measured parts
no faster than passing the slice whole, since V8 already removes what an inlined call
doesn't keep: Chrome's varint decode at 0.98-0.99 times the time and frame decode at
1.01-1.05 over two runs, with the A/A route within 0.05, Firefox and Bun within their
noise, and Node's varint decode at 1.11-1.15.
- A function of the crate's that only translated code calls and that returns a `Result`
of byte slices and scalars, such as `Result<(u64, &[u8]), E>`, whose error is one JS
value that is never `undefined`, writes the `Ok`'s parts into a module-level slot and returns the error or
`undefined`. The slot is shared by every function returning that payload type, named
for the first of them in source order with its suffix, as `readOut` or `leadOut$u16`.
The function writes it at its JS `return`, after its drops, and its caller reads it at
once, so one that returns another's result as is returns the call. The slot's fields
start as `undefined`, so V8 keeps them tagged. When the `Ok`'s first part is a number,
the function returns that, or `undefined` for an error, and writes the error into the
slot instead: V8 boxes a number past 2^31 that a function too big to inline writes into
the long-lived slot, which made Chrome's 8-byte leading-ones varints 1.06-1.09x `main`'s
time. A slice's bytes stay in the slot, since returning them gave back frame decode. The
function as a value is an arrow that rebuilds the `Result`.
- A `BTreeMap` is a B+ tree of up to 64 keys a node, O(log n) as std's B-tree is: its
leaves hold the keys and values and link to their neighbors, which iterators walk from
either end, and its branches hold each child's lower bound. A node's slots shift in a
Expand Down
Loading