perf(bytes): write escaped hex digits directly - #4141
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves Bytes/BytesView escaping performance by writing hex digits directly to a Logger instead of allocating a 2-character String per escaped byte, and validates behavior with a targeted regression test and a benchmark.
Changes:
- Added a private
write_byte_hex(&Logger, Byte)helper inbuiltin/bytesview.mbtto emit two lowercase hex digits without allocating. - Updated
ShowandToJsonimplementations forBytesViewto use the new helper for\xHHescapes. - Added a new behavior test ensuring lowercase hex output, plus a new benchmark test file for
BytesShowandToJsonon binary data.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| builtin/bytesview.mbt | Introduces write_byte_hex and switches BytesView Show/ToJson escaping to direct hex digit writes. |
| builtin/bytes_test.mbt | Adds a regression test asserting exact lowercase \xhh escaping for both Show and ToJson. |
| builtin/bytes_output_bench_test.mbt | Adds benchmarks for Bytes Show/ToJson on 100k binary bytes to quantify the perf impact. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
bobzhang
force-pushed
the
perf/bytes-output-hex
branch
from
August 27, 2026 03:37
a8429c2 to
5781efe
Compare
bobzhang
enabled auto-merge (rebase)
August 27, 2026 03:40
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
Write escaped byte hex digits directly to the output logger instead of allocating a two-character
StringviaByte::to_hex()for every escaped byte. The private helper is shared byShowandToJson.Benchmark
Native release, 100,000 binary bytes:
Bytes ShowBytes ToJsonValidation
moon test builtin --target allmoon checkmoon info(no interface changes)