Repository navigation
perf(ts): number-only small ints, inline from_be_bytes, and indexed byte patterns - #15
Merged
Merged
Conversation
Quest-Claim: e73e630002303297
…patterns Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Pooling makes a byte view's buffer hold other bytes, which consumers can see, so it moves to its own PR for the maintainer to decide. This keeps the README note that a non-allocating Result measured no faster. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
marked this pull request as ready for review
October 24, 2026 08:27
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Collaborator
Author
|
Merging at
(written by Opus 5.5) |
This was referenced Oct 24, 2026
kixelated
added a commit
that referenced
this pull request
Oct 24, 2026
* chore(quest): claim quest/m2/ts-runtime-perf.md Quest-Claim: e73e630002303297 * perf(ts): number-only small ints, inline from_be_bytes, indexed byte patterns Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * perf(ts): pool small byte storage in shared ArrayBuffers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * quest: finish the runtime quest, plan cheaper byte slices Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * test(ts): refresh the fmt snapshot for inline from_be_bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * revert(ts): split pooled byte storage out of this PR Pooling makes a byte view's buffer hold other bytes, which consumers can see, so it moves to its own PR for the maintainer to decide. This keeps the README note that a non-allocating Result measured no faster. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * quest: byte views no longer name rt.bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * perf(ts): pool small byte storage in shared ArrayBuffers Restores the pooling split out of #15 for the maintainer's decision: Vec<u8> storage and [x; N] byte arrays up to 1 KiB share 8 KiB ArrayBuffers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * perf(ts): pool only ByteVec storage, not [u8; N] arrays Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * perf(ts): pool [u8; N] byte arrays again, as ByteVec storage is Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * test(ts): regenerate snapshots for pooled byte arrays Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --------- Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
The first benchmark (#7) put the translated codec's decode at 20-140x slower than moq's hand-written TS, with costs at every integer width. This runs before the wide integer spike so that spike measures only the 64-bit representation.
Approach
Each change was kept only where
just ts benchmeasured a win:rt.ts).u8-u32checks,div,rem, shifts, thechecked/saturating/wrappingfamilies,leading_ones/leading_zeros(Math.clz32), andfrom_be_bytes/to_be_bytesstay in numbers rather than converting tobigint. 64- and 128-bit byte conversions go a 32-bit word at a time, stillbigint.ByteVec.reservecopies its whole storage instead of viewing it.from_be_bytes(library.rs). An array written in place,u32::from_be_bytes([0, 0, a & 0x3f, b]), lowers to((a & 0x3f) << 8) | b, with noUint8Array.of. Any other argument is read uncopied, which dropsrt.copyfrom the varint path.body.rs).let [a, b] = chunkon bytes readschunk[0]andchunk[1]instead of destructuring aUint8Arraythrough its iterator.Split out: pooled byte storage (
rt.bytes) is now draft #24. It changes what a consumer sees, since a view'sbuffermay hold other bytes, so it waits on the maintainer.Measured and dropped:
Result. As an upper bound, a single mutableOkcell made noOkobjects at all. It measured no faster in Node and 0-5% in Bun, soResultkeeps its shape. The README's Design section says so.{ tag: "Short" }). Neutral in Bun, slower in Node (8-byte varint decode went from 124 to 185 ns).?returning the incomingErronly changes error paths, and no workload takes one. Not done.rt.copyperCopytype. No benchmarked path copies after change 2: the onlyrt.copyleft is in version negotiation. Not done.Before and after
ns per item: the median of 15 interleaved samples. Every number below comes from one run, with main's translation loaded as the
A/Aroute. The host has 32 threads shared with other agents' builds, and the load average was 13-16 during the run. A control run with a true A/A put the noise at 3.8% (Node), 6.9% (Bun), and 4.1% (Chrome) at the median workload, and at 19%, 26%, and 29% at most.Each change against the one before it, from A/B runs (the translation before the change loaded as
A/A), measured before the split and unaffected by it:varint/leading-ones/8Bdecode went from 1140 to 237, andgroup/lite-06decode from 2719 to 1216.from_be_bytes: Nodevarint/quic/2Bdecode 170 → 103, frames lite-07 decode 480 → 291; Chrome 144 → 113 and 439 → 255. In Bun the varints stayed within noise.leading-ones/8Bencode 265 → 170. Neutral in V8.The remaining decode gap
Gap = translated − hand-written, in ns per item, split by two ablations of the final translation, each run against the unmodified translation as
A/A:bigintcosts.rest is what is left. When it is negative, moq's own route pays that much overhead that the translation does not. The ablations ran at load averages of 11-23, so a column can be off by the noise above. Chromium, moq's browser target:
Node and Bun
Node v24.21.0
Bun 1.4.2
Workload by workload:
split_first's rest,split_first_chunk's chunk and rest, andlo @ ... Each costs about 20-25 ns in V8 and 40-50 in JavaScriptCore. moq'sCursorreads through an offset and makes none.bigintcosts 13-18 ns at 1 byte in V8, and 35-55 ns at 8 bytes in Node's leading-ones form and in Bun. What is left is within noise in Chrome and Bun; Node leaves 30-50 ns at 2-8 bytes in this run.bigint(30-140 ns) more than cover the gap. Each frame header costs moq'sReader.tryDecodeanother 60-140 ns.Readerper message, which costs more than the translation's 10 views andbigint.Impact
from_be_bytesof an array literal is inline shifts, and of anything else reads it uncopied.[u8; N]patterns index rather than destructure.rt.ts: no exported signature changed.Intkeeps its interface.langcases coverfrom_be_byteson array literals for each narrow width (sign bytes, constant zeros, theu32top bit) and through a reference. The existing differential cases cover the number-only runtime.Alternatives
Okvalues forResult: dropped, since making noOkobjects at all measured no faster.Uint8Array.offor byte literals in encode (asrt.bytesOfwith stores): 10-25% in Bun on the paths that use it, mixed in Node. Left out as encode-only and not clearly a win.Follow-ups
bigintcolumn above is its baseline.just ts benchhung once in Chrome: the renderer sat idle and never posted a result, while a rerun passed. Recommend a timeout inmain.ts'schrome()so a hang fails loudly.Short, would price?reusing the incomingErr.🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
(written by Opus 5.5)