Skip to content

perf(json): avoid allocating strings for 64-bit integers - #786

Open
fallintoplace wants to merge 2 commits into
anthropics:mainfrom
fallintoplace:perf/json-64bit-itoa-20261020
Open

fallintoplace wants to merge 2 commits into
anthropics:mainfrom
fallintoplace:perf/json-64bit-itoa-20261020

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

Avoid allocating a String for each 64-bit JSON integer.

Why

The values must be quoted, but to_string creates a temporary String.

Implementation

  • Format each value with itoa in a stack buffer.
  • Pass the formatted value to the serializer.

Benchmark

Rust 1.95, Ubuntu runner, release build, 11 interleaved samples.

  • int64, 32 values: 742.6 to 407.5 ns/op (1.82x faster).
  • uint64, 32 values: 747.5 to 463.6 ns/op (1.61x faster).
  • int64, 4,096 values: 94.47 to 57.42 us/op (1.65x faster).
  • uint64, 4,096 values: 96.42 to 60.91 us/op (1.58x faster).
  • Benchmark run.

@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