perf(spanner): precompute common headers#8451
Open
surbhigarg92 wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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.
144a301 to
57732ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.envlookups 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.