Skip to content

perf(text): batch long printable bytes when escaping textproto - #794

Open
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:perf/text-bytes-bulk-write-20261021
Open

fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:perf/text-bytes-bulk-write-20261021

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

Write long printable ASCII runs of textproto byte fields in one call.

Why

escape_bytes currently writes printable bytes one at a time.

Implementation

  • Batch the initial printable run when it is at least 32 bytes.
  • Keep the existing escaping loop for the rest.
  • Cover thresholds, control bytes, octal escapes, and mixed input.

Benchmark

Criterion release benchmark on Ubuntu x86-64, AMD EPYC 9V45, Rust 1.95. It reuses a capacity-reserved String. Lower is better.

Input Before After Speedup
Plain 16 B 11.282 ns 11.466 ns 0.98x
Plain 64 B 51.279 ns 21.258 ns 2.41x
Plain 256 B 177.27 ns 93.047 ns 1.91x
Plain 4 KiB 2.6838 µs 1.2865 µs 2.09x
Plain 64 KiB 44.213 µs 20.953 µs 2.11x
Mixed 4 KiB 2.6748 µs 1.6345 µs 1.64x
Binary 4 KiB 6.8575 µs 6.5090 µs 1.05x
Escaped 256 B 178.15 ns 170.60 ns 1.04x

The 16 B and escaped cases were not statistically significant. The final commit only changes an equivalent Clippy range check from the measured implementation. Benchmark output.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant