Skip to content

perf(spanner): eliminate per-RPC regex operations in metrics layer - #9308

Open
olavloite wants to merge 2 commits into
mainfrom
spanner-eliminate-regex-on-hot-path
Open

olavloite wants to merge 2 commits into
mainfrom
spanner-eliminate-regex-on-hot-path

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Replaces regular expression matching across hot RPC metrics pathways with direct string searching and delimiter-based parsing:

  • Extracts GFE and AFE Server-Timing latencies using delimiter checks and ASCII digit accumulation, avoiding per-RPC regex instantiation and string allocations.
  • Replaces named-capture regular expressions in resource name parsing with positional path segment inspection.
  • Replaces regex parsing in request ID operation extraction with a single-pass delimiter scan.
  • Updates latency checks in the interceptor and tracer to explicitly check for numeric types, ensuring 0 ms latencies are recorded accurately instead of misclassified as connectivity errors.

Replaces regular expression matching across hot RPC metrics pathways with direct string searching and delimiter-based parsing:

- Extracts GFE and AFE Server-Timing latencies using delimiter checks and ASCII digit accumulation, avoiding per-RPC regex instantiation and string allocations.
- Replaces named-capture regular expressions in resource name parsing with positional path segment inspection.
- Replaces regex parsing in request ID operation extraction with a single-pass delimiter scan.
- Updates latency checks in the interceptor and tracer to explicitly check for numeric types, ensuring 0 ms latencies are recorded accurately instead of misclassified as connectivity errors.
@olavloite
olavloite requested a review from a team as a code owner September 13, 2026 07:15
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 13, 2026

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

Copy link
Copy Markdown
Contributor

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 refactors metrics tracking and tracing in the Spanner client to eliminate regex allocations and improve performance. Specifically, it replaces regex-based parsing with manual string splitting and character-by-character parsing for extracting instance attributes, operation requests, and server-timing latencies (GFE and AFE). It also updates latency checks to explicitly verify number types, enabling support for zero-latency values, and adds comprehensive unit tests to validate these optimizations and edge cases. There are no review comments, so I have no feedback to provide.

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

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant