Skip to content

perf(spanner): use StringBuilder for generating RequestId#12809

Open
olavloite wants to merge 3 commits intomainfrom
spanner-optimize-request-id-generation
Open

perf(spanner): use StringBuilder for generating RequestId#12809
olavloite wants to merge 3 commits intomainfrom
spanner-optimize-request-id-generation

Conversation

@olavloite
Copy link
Copy Markdown
Contributor

Use a StringBuilder instead of String.format(..) to generate the header value of a RequestId. This significantly reduces the CPU time needed. Generating the header value for 10mio RequestIds using the new/old implementation take:

  • Old: 2750ms
  • New: 203ms

Use a StringBuilder instead of String.format(..) to generate the header value
of a RequestId. This significantly reduces the CPU time needed. Generating the
header value for 10mio RequestIds using the new/old implementation take:

- Old: 2750ms
- New: 203ms
@olavloite olavloite requested review from a team as code owners April 15, 2026 13:25
@olavloite olavloite changed the title chore(spanner): use StringBuilder for generating RequestId perf(spanner): use StringBuilder for generating RequestId Apr 15, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes the generation of Spanner request IDs by pre-calculating static and instance-specific prefixes and replacing String.format with StringBuilder in getHeaderValue and toString. The review feedback suggests using a more precise initial capacity for the StringBuilder instances, calculated from the instancePrefix length, to avoid potential internal array resizes in high-throughput paths.

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.

4 participants