Skip to content

perf(spanner): avoid cloning metadata map in metrics interceptor - #9307

Merged
olavloite merged 1 commit into
mainfrom
spanner-stop-cloning-metadata-map
Sep 14, 2026
Merged

olavloite merged 1 commit into
mainfrom
spanner-stop-cloning-metadata-map

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

MetricInterceptor previously called metadata.getMap() to read the server-timing response header. getMap() constructs a fresh object and copies every response header, creating unnecessary allocations and iteration overhead on every RPC attempt.

This change replaces getMap() with a direct metadata.get('server-timing') lookup, reading the header value without cloning the entire metadata dictionary.

MetricInterceptor previously called metadata.getMap() to read the
server-timing response header. getMap() constructs a fresh object
and copies every response header, creating unnecessary allocations
and iteration overhead on every RPC attempt.

This change replaces getMap() with a direct metadata.get('server-timing')
lookup, reading the header value without cloning the entire metadata
dictionary.
@olavloite
olavloite requested a review from a team as a code owner September 13, 2026 05:44
@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 updates the MetricInterceptor to retrieve the server-timing header using metadata.get('server-timing') instead of metadata.getMap(), extracting the first entry if available. It also adds a corresponding unit test to verify this behavior and removes BOM characters from the copyright headers. There are no review comments, so no feedback is provided.

@olavloite
olavloite merged commit 6eec761 into main Sep 14, 2026
50 checks passed
@olavloite
olavloite deleted the spanner-stop-cloning-metadata-map branch September 14, 2026 06:36
danieljbruce pushed a commit that referenced this pull request Sep 14, 2026
🤖 I have created a release *beep* *boop*
---


##
[8.13.0](spanner-v8.12.0...spanner-v8.13.0)
(2026-09-14)


### Features

* PNPM workspace
([#8973](#8973))
([1ea27c9](1ea27c9))


### Bug Fixes

* **spanner:** Do not execute queued queries on ended transactions
([#9305](#9305))
([f74f198](f74f198))


### Performance Improvements

* **spanner:** Avoid cloning metadata map in metrics interceptor
([#9307](#9307))
([6eec761](6eec761))
* **spanner:** Avoid redundant clock reads in isGlobalTracingEnabled
([#9311](#9311))
([c42f144](c42f144))
* **spanner:** Bypass stream pipeline for single-chunk query results
([#9279](#9279))
([e46a407](e46a407))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
thiyaguk09 pushed a commit to thiyaguk09/google-cloud-node-fork that referenced this pull request Sep 15, 2026
🤖 I have created a release *beep* *boop*
---


##
[8.13.0](googleapis/google-cloud-node@spanner-v8.12.0...spanner-v8.13.0)
(2026-09-14)


### Features

* PNPM workspace
([googleapis#8973](googleapis#8973))
([1ea27c9](googleapis@1ea27c9))


### Bug Fixes

* **spanner:** Do not execute queued queries on ended transactions
([googleapis#9305](googleapis#9305))
([f74f198](googleapis@f74f198))


### Performance Improvements

* **spanner:** Avoid cloning metadata map in metrics interceptor
([googleapis#9307](googleapis#9307))
([6eec761](googleapis@6eec761))
* **spanner:** Avoid redundant clock reads in isGlobalTracingEnabled
([googleapis#9311](googleapis#9311))
([c42f144](googleapis@c42f144))
* **spanner:** Bypass stream pipeline for single-chunk query results
([googleapis#9279](googleapis#9279))
([e46a407](googleapis@e46a407))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
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.

2 participants