Skip to content

perf(json): avoid intermediate strings for small bytes fields - #781

Open
fallintoplace wants to merge 2 commits into
anthropics:mainfrom
fallintoplace:perf/json-base64-small-stack-20261019
Open

fallintoplace wants to merge 2 commits into
anthropics:mainfrom
fallintoplace:perf/json-base64-small-stack-20261019

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

  • Avoid a temporary heap string when encoding bytes fields up to 192 bytes.

Why

  • Small ProtoJSON bytes fields currently allocate a String for base64 output.

Implementation

  • Encode up to 192 input bytes into a 256-byte stack buffer.
  • Keep the existing path for larger fields.

Benchmark

  • New vs old, Criterion (80 samples, 2 runs): 8/32/96/192 B: 23/43/92/176 ns vs 50/70/121/201 ns.
  • 193 B: 205-210 ns vs 205-208 ns. 4096 B: 3.39-3.40 us both; no measurable change.

@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