Repository navigation
perf(ts)!: lower byte slices to rt.ByteSlice, splitting without a view #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5b233c1
chore(quest): claim quest/m2/ts-byte-views.md
kixelated 34c9d7b
perf(ts): lower byte slices to rt.ByteSlice, splitting without a view
kixelated 1f9e8d0
docs(ts): byte slices in the README, and the quest's remaining work
kixelated ea0d617
Merge remote-tracking branch 'origin/main' into quest/m2/ts-byte-views
kixelated a4e7a93
fix(ts): refuse copy_within of other than bytes, whose Copy aggregate…
kixelated ff5444e
Merge remote-tracking branch 'origin/main' into quest/m2/ts-byte-views
kixelated 1e20bcc
fix(ts): convert only the bytes being unsized to a ByteSlice
kixelated 9e46008
Merge remote-tracking branch 'origin/main' into pr82
kixelated 57fc224
Merge remote-tracking branch 'origin/main' into pr82
kixelated 3318e3c
Merge remote-tracking branch 'origin/main' into pr82
kixelated 26bab2f
Merge origin/main into ts-byte-views
kixelated 53379e5
Merge origin/main into ts-byte-views
kixelated cb7d66d
Merge origin/main into ts-byte-views
kixelated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,26 @@ | ||
| # [L] Cheaper byte slices | ||
| # [L] Byte slices without objects | ||
|
|
||
| ## Goal | ||
|
|
||
| Splitting a `&[u8]` in translated code stops costing a `Uint8Array` view per | ||
| split, so the codec's decode on the [TS benchmark](/ts/README.md#bench) moves | ||
| toward moq's hand-written cursor, with every differential test still passing. | ||
| Splitting a `&[u8]` in translated code allocates nothing, so the codec's decode on the | ||
| [TS benchmark](/ts/README.md#bench) moves toward moq's hand-written cursor, with every | ||
| differential test still passing. | ||
|
|
||
| ## Plan | ||
|
|
||
| The report in PR #15 puts views at most of what decode still costs: | ||
| about 25 ns each in V8, and a varint takes one to four (`split_first`'s rest, | ||
| `split_first_chunk`'s chunk and rest, a `lo @ ..` pattern). moq's hand-written | ||
| `Cursor` reads through an offset and makes none. | ||
| `&[u8]` is an `rt.ByteSlice`, a range of a `Uint8Array`, so a split makes an object | ||
| rather than a view. What decode still pays per varint: | ||
|
|
||
| Options to measure, not a decision: | ||
| - `split_first_chunk`'s chunk is a `&[u8; N]`, which is a `Uint8Array` view of the | ||
| slice's bytes: one per multi-byte varint. A chunk only indexed could read the slice in | ||
| place, or a reference to a byte array could be a `ByteSlice` too. | ||
| - Each split's rest is a new `ByteSlice`, and its tuple and `Result` are objects. Byte | ||
| slices in locals, parameters, and fields could be scalar-replaced as `(data, start, | ||
| length)`, as `u64` halves are, materializing a `ByteSlice` only where one escapes. | ||
| A microbenchmark of QUIC varint decode measured offsets in locals about 2x faster than a | ||
| `ByteSlice` per split in V8 and about the same in JavaScriptCore. | ||
| - Iterating a byte slice makes one view, which `rt.iterSlice` and stepping in place read. | ||
|
|
||
| - Lower `&[u8]` to an offset and length into a shared array, as `(buf, start, | ||
| end)` locals the translator scalar-replaces, materializing a `Uint8Array` | ||
| only at the API edge. | ||
| - Keep `Uint8Array` but skip views nothing reads: a split whose chunk is only | ||
| destructured into bytes, or whose rest is unused on the path taken. | ||
|
|
||
| Engines differ: JavaScriptCore makes views slower than V8 but small copies | ||
| faster, and V8 gives a lone small array its own buffer, about a microsecond, | ||
| the first time it is viewed. Measure Node, Bun, and Chrome. | ||
| Measure Node, Bun, and Chrome, and Firefox once the bench has it; Chrome decides. | ||
|
|
||
| Public API: the translator's output for byte slices. |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing TypeScript callers must now wrap
Uint8Arrayarguments withbyteSliceFromand unwrap returned slices withbyteSliceView; runtime exports also change or disappear. However,ts/MIGRATE.mdhas no entry describing this migration. The commit explicitly omits it because the project is pre-release, butAGENTS.mdrequires anUnreleasedentry for every breaking change without that exception. Add the parameter/result conversion instructions and changed runtime exports to the migration guide so existing consumers can update correctly.AGENTS.md reference: AGENTS.md:L46-L46
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not adding one. The maintainer's brief for this work says no MIGRATE.md entries while rust2 is pre-release. The PR body's Impact section lists the breaking API change and how callers convert. Whether to require MIGRATE.md entries before a first release is the maintainer's call.
(written by Opus 5.5)