Repository navigation
perf(ts): pool small byte storage in shared ArrayBuffers - #24
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
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
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
kixelated
marked this pull request as ready for review
October 24, 2026 19:45
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
|
Summary before merge, at 05807ac:
(written by Opus 5.5) |
This was referenced Oct 25, 2026
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
V8 gives a lone small byte array its own
ArrayBuffer, about a microsecond apiece: past 64 bytes when the array is made, and below that the first time something views it. Encoding a size-prefixed message pays that twice. This was change 4 of #15, split out because it changes what a consumer sees.Approach
ByteVec's storage and[u8; N]arrays come frombytes(n)inrt.ts. Up to 1 KiB, it hands out views of 8 KiBArrayBufferslabs, 8-byte aligned, as Node'sBufferpool does. No byte is handed out twice. A[x; N]ofu8lowers tort.bytes(N), per decision 2.Decisions
Keep pooled byte storage?
ByteVecand[x; N]arrays.ByteVec, leaving[x; N]arrays unpooled. Superseded by decision 2.Merge (c) now that it is measured? Pooling only
ByteVeckeeps the whole group decode cost but loses most of the encode win: the[u8; 9]size prefix inEncoderwas carrying it. The earlier "Bun varint decode 10-30% slower" was the bench's route slot, not pooling: Bun runs identical code 17-38% slower astranslatedthan asA/A. With that bias removed, both variants cost group decode about the same.Each pair is lite-06, lite-07.
The maintainer chose (a).
Measured
ns per item: the median of 15 interleaved samples from
just ts benchon a 32-thread host shared with other builds and another agent's bench, at load averages of 13-33, with one spike to 63. Main's translation was loaded in place ofA/A, once forward (pooled astranslated, main asA/A) and once reversed. A slot biasbmakes forwardf = p·band reversedr = b/p, so the change isp = √(f/r), with the two forward runs of (c) averaged geometrically. A true A/A control put the noise at 6.8% (Node), 12% (Bun), and 3.0% (Chrome) at the median workload, and 22%, 73%, and 53% at most. In Chrome and Bun, pooled group decode was slower in all six measurements of (c).ByteVec only (c), main → pooled:
Full pool (a), main → pooled:
Sanity run of the merged head (05807ac), with main's translation as a
--route(#37), forward only, at load average 27. Translated → main ns per item, lite-06 and lite-07:Encode still halves or better everywhere, and decode still costs some in Bun and Chrome.
Impact
ByteVec's storage or a[u8; N]up to 1 KiB may share anArrayBufferwith other bytes. A consumer reads its view throughbyteOffsetandbyteLength, and copies it before transferring its buffer. The README says so.rust2-tshas noMIGRATE.md.rt.tsexportsbytes(n), which generated[u8; N]code calls.Alternatives
ByteVecoff V8's heap from the start: any lone buffer costs V8 the same microsecond, so only sharing one avoids it.Follow-ups
translatedslot runs 17-38% slower thanA/Ain Bun on identical code, so any A/B throughA/Aneeds a reversed run. Alternating which route runs first would remove the bias; another PR is fixing it.🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
(written by Opus 5.5)