Repository navigation
perf(ts): pass byte slices as their parts, and return Results of them in a slot - #160
Merged
Merged
Conversation
Quest-Claim: c39cdeba9d4b6c36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A function only translated code calls that returns a Result of byte slices and scalars returns its error or undefined and writes the Ok's parts into a slot shared per payload type, whose fields start undefined so V8 keeps them tagged. Callers read the slot at once; a call returned as is forwards it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/expected/refs.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
added a commit
that referenced
this pull request
Oct 29, 2026
…s reserve A handle never split nor taken from a Bytes is bytes' vector kind, whose offset and capacity rt.BytesMut now keeps exactly, so it grows and panics as Vec does. Once storage was shared or taken, bytes' capacity depends on which handles dropped, so reserve throws a rust2-ts error past 512 MiB, counting what the handle read past; below that, bytes' storage stays under 1 GiB and grows without panicking whichever handles dropped. The stock fixture's caller names inputs at the limit's edges, and a runtime test checks the throw. Drops the bench quest, which #160 fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The slot is now one of main's Item::Value module values, whose pure mark goes only on a call or new, since Rollup warns of one on a literal. Only functions take parts or a slot, as main lowers thread-locals' consts as instances too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
added a commit
that referenced
this pull request
Oct 29, 2026
* chore(quest): claim quest/m2/ts-model/bytes.md Quest-Claim: 52d3e75868421f10 * feat(ts): map bytes' BytesMut, Buf, and BufMut without config BytesMut is an rt.BytesMut, a window of storage that split_to, split, and freeze share without overlapping. Buf and BufMut of Bytes, BytesMut, &[u8], and Vec<u8> map to rt/bytes.ts with bytes' panics; the rest of bytes translates from its MIR. BytesMut's capacity, which depends on whether other handles dropped, is refused. moq's model.toml drops its BytesMut binding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(quest): plan a BytesMut's exact capacity Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(quest): title the BytesMut capacity quest as quest check requires Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ts): refuse BufMut::put of a crate's own Buf into a BytesMut bytes calls the source's copy_to_bytes or its chunk and advance by whether the BytesMut's capacity is zero, which depends on whether other handles of its storage dropped. rt.BytesMut can't tell, so the calls a crate's own Buf sees could differ. Put into a Vec<u8> stays mapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ts): throw on Bytes::slice_ref of bytes from other storage Rust may share storage that the translation copies, such as a &'static str's bytes, which as_bytes encodes anew, so a subset from another buffer may be one Rust accepts. Throw a rust2-ts error there instead of panicking as if Rust would. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ts): track when a BytesMut's storage kind depends on drops bytes keeps shared storage shared when it grows with no other handle alive, and makes it a vector when one is, so after shared storage grows, after From<Bytes>, and after a vector's put of a Bytes or BytesMut, its kind is unknown here. A reserve past usize::MAX, whose panic message is "overflow" for shared storage and "capacity overflow" for a vector, throws a rust2-ts error there instead of guessing. The stock fixture reserves past usize::MAX only into handles sure of their kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ts): grow a BytesMut vector as Vec does and limit shared storage's reserve A handle never split nor taken from a Bytes is bytes' vector kind, whose offset and capacity rt.BytesMut now keeps exactly, so it grows and panics as Vec does. Once storage was shared or taken, bytes' capacity depends on which handles dropped, so reserve throws a rust2-ts error past 512 MiB, counting what the handle read past; below that, bytes' storage stays under 1 GiB and grows without panicking whichever handles dropped. The stock fixture's caller names inputs at the limit's edges, and a runtime test checks the throw. Drops the bench quest, which #160 fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(quest): name the std calls bytes' getters need in ts-unsafe Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d btree/ aren't Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/src/lower/body.rs
…vironment Main's `lowers` now takes the typing environment of the body naming the instance; `inside` has none, so it takes the crate's, as `translated` does. Regenerates the lang fixture's snapshots after the merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/core/option.ts # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
A parameter passed as its parts that the body makes into an object, at entry or at a use, only moves that object from the caller into the callee. Through `take_u64` that made Chrome's `btree/` workloads 1.06x `main`'s time. `parted` now runs the callee's own analysis and keeps a slice as parts only where the body holds it so and never makes it. A body's answer depends on what its callees take, so the instances a call reaches settle together as a greatest fixpoint, recursion included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al's whole error A slotted producer copies none of its arguments, and may take none, so reading its first argument panicked. `?` on a residual held as its parts passed `From::from` only the error's first part; it now makes the whole `Err` from that variant's parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
kixelated
enabled auto-merge (squash)
November 1, 2026 03:44
moq-bot Bot
pushed a commit
that referenced
this pull request
Nov 1, 2026
Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: moq-bot <moq-bot@users.noreply.github.com>
This was referenced Nov 1, 2026
kixelated
added a commit
that referenced
this pull request
Nov 1, 2026
A function only translated code calls that returns a Result of numbers alone, such as Decoder::varint's Result<u64, E> or a Result<(i64, u64), E>, now hands back through #160's slot: it returns the first number, or undefined with the error in the slot, and writes any other numbers there. A local with no slice is held as its parts only where it meets a slot, and a tuple made where its parts are taken apart is never made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moq-bot Bot
pushed a commit
that referenced
this pull request
Nov 1, 2026
* chore(quest): claim quest/m2/ts-byte-views/README.md Quest-Claim: 00e3717952d0d17a * perf(ts): return a Result of numbers alone in a slot A function only translated code calls that returns a Result of numbers alone, such as Decoder::varint's Result<u64, E> or a Result<(i64, u64), E>, now hands back through #160's slot: it returns the first number, or undefined with the error in the slot, and writes any other numbers there. A local with no slice is held as its parts only where it meets a slot, and a tuple made where its parts are taken apart is never made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(ts): update results' snapshot for #381's merge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(ts): regenerate core/result.ts's snapshot for #384's merge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: quest fixer <quest-fixer@localhost>
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.
Claims quest/m2/ts-byte-views/returns.md, which absorbs
arguments.md.Problem
Reading through a translated cursor makes an object per split, and a fallible read returns
rt.Ok([value, new rt.ByteSlice(...)]): three objects per varint. Passing&[u8]parameters as their parts alone gained nothing in Chrome; the win needs the return side too.Decided
undefined. Land only if Chrome wins on both varint and frame decode, with the A/A under 5% at the median and the max.main), measuring the alternatives, and pick the one that removes it without giving back the decode wins.time/andbtree/must not regress at the family level.btree/gap (1.06xmain, fromtake_u64rebuilding the sliceorderedpassed as parts): keep a&[u8]parameter whole when the callee would rebuild it anyway, worked out across calls that pass a slice along, covering recursion, mutual recursion, and a function only some of whose callers pass parts. Same bar, withbtree/andtime/judged against main-vs-main noise.Approach
Parameters as parts: a function only translated code calls takes a
&[u8]/&[u8; N]asdata, start, lengthonly when its body holds that slice as parts and never makes its object.take_u64rebuilding the sliceorderedpassed, that made Chrome'sbtree/1.06xmain.Translator::partedruns the callee's own analysis (Fx::newon a throwaway body, with refusals held back) and checks two things: whether the parameter lands inscalars, and whether no read makes its object (remade, whichunheldnow reports).Decoder::new,take_u64, and the bench's entry points take the slice whole, as onmain.Results in a slot: a function of the crate's that only translated code calls, and that returns
Result<T, E>, qualifies when:undefined(not(), anOption, or a type parameter).It hands back the
Ok's parts through a module-levelconstslot shared per T, such asreadOut. There are two return shapes:read,read_quic,read_leading_ones): the function returns that number, orundefinedfor an error. The rest of the parts go in the slot, and an error goes in the slot'serrfield. The caller readserrright after the call and branches on it.Decoder::slice,bytes): the function returnsE | undefined, with every part in the slot.Details shared by both:
undefined as never._0as parts and writes the slot at the JSreturn, after its drops. An assignment of_0that runs straight into a return returns right there.?'sFromResidual::from_residualis a producer, so an earlyreturn Errstays a bare return._0that returns straight away through the same slot is justreturn call(...).inspect_err, a closure) rebuilds theResultat once. A function used as a value is wrapped in an arrow that rebuilds it.leadOut$u16, and the census of names declares each…Out.Why the number is returned: the old ABI wrote every part into the slot. The slot is long-lived, and V8 boxes a number past 2^31 written into it by a function too big to inline (
read_leading_ones). That put Chrome's 8-byte leading-ones varints at 1.16xmainon the old bench and 1.06-1.09x on fix(ts): time each bench round in fresh workers #360's. A slice's bytes stay in the slot, since returning them gave back frame decode.Alternatives measured for the 8-byte case, in Chrome, against this branch before the change (three runs each):
p_0starts at0erron every callerronly on failureThe last row lost about 7% of frame decode to the failure-only hand edit. Reading
errfirst and branching on it recovered that, which is the shape here.Measurements
tasksetto P-cores 4-7.mainat5433a3e8; this branch at6c614fb7, whose codec output the review fixes keep.main, and two ofmainagainst itself, to size the noise.coding/varint.ts,coding/decode.Decoder.ts, and the differentialharness.ts.bench.ts, which holds thebtree/,time/,iter/, andorder/workloads, is byte-identical tomain's.Time as a fraction of
main's, family geomeans per run (below 1 is faster), Chrome, with the family's A/A gap:btree/maptime/add, compare, convertmainagainstmainbtree/andtime/: withinmain-against-mainnoise. That noise is up to 5% forbtree/and 13% fortime/add, on identical code. The one outlier, run 2'stime/compare at 1.19, did not repeat (1.03, 1.00, 0.99). It is identical code on both sides.main, against 1.06-1.09x before the slot returned the number.btree/0.97-1.08 across the three, with Node's 1.08 in run 3 beside a 39% A/A on that run'stime/add.a30214d5, 2026-10-31): Chromebtree/was 1.07, 1.15, 1.01 in three runs and 1.06, 0.99, 1.07 with routes swapped. Hand-restoringorderedandtake_u64tomain's text took it to 0.97, 0.99, 0.98, which the rule now does.Impact
data, start, length;Resultreturns its first number or its error, with the rest in a…Outslot exported beside it.MIGRATE.mdsays both. The lang fixture's hand-writtenbrands.tsnow passestail_breakits slice whole, since that function makes it in a loop.Uint8Arrayreference) alive until the next write.Decoder::slice,bytes, andvarint::read*).just ts moqtranslates and type-checks it.Alternatives
Okassignment would be wrong when drops run between that assignment and the return. So the writes happen at the return, and an assignment returns early only when nothing runs in between.Checks
just cipasses locally on this head, after mergingorigin/main(5433a3e8).args::argsruns differentially against native wasm32 on 50k random inputs. Its new arms cover:relay), so it is taken whole too, and one passed to a function holding parts (relay_sum), which stays parts;last_run, whole all the way down);evensandodds, both parts);pingwhole,pongparts);sum,relay,relay_sumon stored halves and on a parameter).returns::returnskeeps its earlier coverage and adds:fixed);?whose residual error is a slice and a byte, converted (wrapped).remadetest, so a slice the body makes stays parts, fails the lang snapshot.errmade the differential report 88 differences.Review
quest reviewwith Codex, gpt-6.1-sol at medium effort, againstorigin/main(fbcd2582).6c614fb7raised two findings, both fixed inbfa1dbbcand reproduced first with new lang cases:&args[0]inscalar.rs.produced_copynow reads the first argument only if there is one. The case isreturns::fixed.?on a residual held as parts passedFrom::fromonly the error's first part, whichtscrejected. TheErris now built from its variant's parts. The case isreturns::wrapped.bfa1dbbc: no findings.(written by Claude Opus 5.5)
🤖 Generated with Claude Code