Skip to content

perf(spanner): optimize prepareGapicRequest dispatch and eliminate deep cloning - #9271

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-prepare-gapic-request
Open

perf(spanner): optimize prepareGapicRequest dispatch and eliminate deep cloning#9271
olavloite wants to merge 1 commit into
mainfrom
spanner-prepare-gapic-request

Conversation

@olavloite

Copy link
Copy Markdown
Contributor
  • Dispatch RPCs synchronously once the project ID is resolved, eliminating an asynchronous auth callback hop on every query and mutation.
  • Avoid recursive deep-cloning (extend) of request payloads and GAX options on the hot path by inspecting only top-level resource name keys.
  • Coalesce concurrent auth.getProjectId lookups during client cold start.
  • Fix duplicate RPC execution in wrappedRequestFn for Promise-based calls.

@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 9, 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 optimizes prepareGapicRequest_ in the Spanner class by avoiding unnecessary deep cloning of reqOpts when the project ID is already cached, and introduces a helper function hasProjectIdToken to detect placeholders. The reviewer's feedback highlights critical issues regarding potential double-callback invocations if a callback throws an error, and recommends deep cloning gaxOpts instead of shallow copying it to protect the user's original configuration from accidental mutation.

Comment thread handwritten/spanner/src/index.ts
Comment thread handwritten/spanner/src/index.ts Outdated
Comment thread handwritten/spanner/src/index.ts Outdated
…ep cloning

- Dispatch RPCs synchronously once the project ID is resolved, eliminating
  an asynchronous auth callback hop on every query and mutation.
- Avoid recursive deep-cloning (extend) of request payloads and GAX options
  on the hot path by inspecting only top-level resource name keys.
- Coalesce concurrent auth.getProjectId lookups during client cold start.
- Fix duplicate RPC execution in wrappedRequestFn for Promise-based calls.
@olavloite
olavloite force-pushed the spanner-prepare-gapic-request branch from 9912bda to d90997f Compare September 9, 2026 09:53
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces a new helper function hasProjectIdToken and refactors prepareGapicRequest_ in the Spanner client to coalesce concurrent auth.getProjectId calls, preventing redundant asynchronous lookups. It also improves error handling, ensures request IDs are attached to stream and callback errors, and adds comprehensive unit tests. The reviewer suggested optimizing the first-request path by bypassing auth.getProjectId entirely if a resolved projectId is already provided in the constructor.

Comment thread handwritten/spanner/src/index.ts
@olavloite
olavloite marked this pull request as ready for review September 9, 2026 13:21
@olavloite
olavloite requested a review from a team as a code owner September 9, 2026 13:21
@github-actions
github-actions Bot requested a review from shivanee-p September 9, 2026 13:22
@shivanee-p
shivanee-p removed their request for review September 9, 2026 15:51
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