perf(bytes): skip redundant initialization in concatenation - #4142
Open
mizchi wants to merge 3 commits into
Open
perf(bytes): skip redundant initialization in concatenation#4142mizchi wants to merge 3 commits into
mizchi wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes Bytes concatenation on non-JS targets by avoiding redundant zero-initialization, while keeping the existing JS implementation for compatibility.
Changes:
- Refactors
Bytes + Bytesto delegate to a target-specificbytes_add_impland uses uninitialized allocation + blits on non-JS targets. - Adds a regression test to ensure the concatenation result is fully initialized and correctly contains both inputs.
- Adds a benchmark covering large
Bytesconcatenation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| builtin/bytes.mbt | Implements a non-JS fast path for Bytes::add using uninitialized allocation and two blits; keeps the JS path unchanged. |
| builtin/bytes_test.mbt | Adds a test validating Bytes::add initializes and populates the full result correctly. |
| builtin/bytes_add_bench_test.mbt | Introduces a benchmark for large Bytes concatenation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
Avoid zero-initializing the concatenation result on non-JS targets before both inputs overwrite the full allocation. Allocate uninitialized storage, fill the two non-overlapping ranges with blits, then reinterpret the fully initialized buffer as
Bytes. JS keeps the existing implementation because the required intrinsic is unavailable there.Benchmark
Native release, 500,000 + 500,000 bytes:
Validation
moon test builtin --target allmoon checkmoon info(no interface changes)