Skip to content

perf(spanner): precompute common headers#8451

Open
surbhigarg92 wants to merge 2 commits into
mainfrom
spanner_optimize_headers
Open

perf(spanner): precompute common headers#8451
surbhigarg92 wants to merge 2 commits into
mainfrom
spanner_optimize_headers

Conversation

@surbhigarg92
Copy link
Copy Markdown
Contributor

@surbhigarg92 surbhigarg92 commented Jun 7, 2026

Optimizes Spanner request performance by pre-computing static headers during client initialization and propagating them down to sub-resources (Instance, Database, Session, and Transaction). This eliminates expensive process.env lookups and string formatting on the request hot path by replacing dynamic getCommonHeaders calls with fast, native object spread clones (...).

Unit tests and mock objects have been updated accordingly to align with the new constructor signatures.

@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Jun 7, 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 refactors the construction of commonHeaders_ across several Spanner client classes (Database, Instance, Session, and Snapshot) by copying parent headers using Object.assign and appending the CLOUD_RESOURCE_HEADER where appropriate. The feedback highlights critical issues in the test files where newly introduced constants (AFE_SERVER_TIMING_HEADER and CLOUD_RESOURCE_HEADER) are used without being imported, which will lead to runtime errors. Additionally, it is recommended to use the more idiomatic TypeScript object spread operator (...) instead of Object.assign for better readability and type safety.

Comment thread handwritten/spanner/test/database.ts
Comment thread handwritten/spanner/test/instance.ts
Comment thread handwritten/spanner/test/session.ts
Comment thread handwritten/spanner/test/transaction.ts
Comment thread handwritten/spanner/src/database.ts Outdated
Comment thread handwritten/spanner/src/instance.ts Outdated
Comment thread handwritten/spanner/src/session.ts Outdated
Comment thread handwritten/spanner/src/transaction.ts Outdated
@surbhigarg92 surbhigarg92 force-pushed the spanner_optimize_headers branch from 144a301 to 57732ca Compare June 8, 2026 14:17
@surbhigarg92 surbhigarg92 marked this pull request as ready for review June 8, 2026 14:18
@surbhigarg92 surbhigarg92 requested a review from a team as a code owner June 8, 2026 14:18
@surbhigarg92 surbhigarg92 changed the title feat(spanner): precompute common headers perf(spanner): precompute common headers Jun 8, 2026
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