GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(spanner): optimize query result decoding by olavloite · Pull Request #17375 · googleapis/google-cloud-python

Conversation

@olavloite

@olavloite olavloite commented Jun 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Work in progress.

Optimizes the decoding and reading of (large) result sets for Spanner.

image

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@olavloite
perf(spanner): optimize query result decoding
9d80835
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Jun 4, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 optimizes performance across Spanner streaming and helper modules by caching list append methods, pre-compiling regular expressions, and replacing helper functions with direct attribute getters or lambdas. However, several critical issues were identified in _helpers.py: missing imports for datetime and base64 will cause runtime errors, BYTES values are incorrectly encoded to UTF-8 instead of being base64-decoded, and the new timestamp parsing logic ignores timezone offsets for non-UTC inputs, resulting in incorrect times.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@olavloite
perf: further optimizations + timestamp fix
7820f5c
@olavloite

olavloite commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot]
gemini-code-assist Bot reviewed Jun 4, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 introduces several performance optimizations to the Spanner client library, such as caching local variables and methods during row merging, using lambdas and operator.attrgetter for type decoding, pre-compiling regex patterns, and optimizing timestamp parsing. The reviewer provided valuable feedback to further boost performance, including checking the more common number_value field first for float decoding, using string slicing instead of regular expressions for timestamp parsing, and removing the unused re import.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@olavloite
chore: address review comments
10173de
@olavloite

olavloite commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

The time needed to decode 100,000 rows is significantly reduced from approx 6-7s to approx 3-3.5s. The increasing gap between the two lines is due to the nature of this benchmark. The benchmark simulates a randomized poisson load. A small burst in traffic is enough to completely overload the old implementation, and cause requests to queue up and start taking an exponentially increasing time.

image
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@olavloite
olavloite marked this pull request as ready for review June 4, 2026 16:30
@olavloite
olavloite requested a review from a team as a code owner June 4, 2026 16:30
@olavloite olavloite changed the title perf(spanner): [WIP] optimize query result decoding perf(spanner): optimize query result decoding Jun 4, 2026
rahul2393
rahul2393 approved these changes Jun 4, 2026
View reviewed changes

@rahul2393 rahul2393 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - with minor comments/questions and test assert fix

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py
if val[19] == ".":
if val.endswith("Z"):
offset = "Z"
fraction = val[20:-1]

@rahul2393 rahul2393 Jun 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spanner Timestamp seems to be always UTC Z at the API/wire level. Non-Z offset only come from CAST(ts as String), which is a STRING column and routes through the STRING decoder.

+/-HH:MM handling plus the astimezone call won't ever be executed on real TIMESTAMP value? Can we drop it to shrink the risky code, or comment marking it deliberately defensive. The Z fast-path is the legitimate win and short-circuits before this anyway?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that Spanner (currently) always sends timestamps in Zulu time. BUT: It is not strictly part of the API contract, meaning that future feature changes in Spanner could (in theory) trigger timestamps to be sent with an offset. Also, the previous implementation also supported offsets, so I included this in order not to cause any potential regressions from the previous implementation.

I added an additional test for parsing timestamps with an offset (in this case one without a sub-second fraction).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rahul2393 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread packages/google-cloud-spanner/tests/unit/test__helpers.py

parsed = self._callFUT(value_pb, field_type, field_name)
self.assertIsInstance(parsed, datetime_helpers.DatetimeWithNanoseconds)
self.assertEqual(parsed, expected)

@rahul2393 rahul2393 Jun 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DatetimeWithNanoseconds.eq is inherited from datetime and compares only to microsecond - it ignores .nanosecond. So this passes even if sub-us digits are wrong.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, great catch, thanks! I updated the various checks in all the tests in this file, and also added a test that would otherwise have reported a false positive.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_async/streamed.py
index = 0
else:
for value in values:
if value.HasField("null_value"):

@rahul2393 rahul2393 Jun 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value.HasField("null_value") duplicates _parse_nullables's semantics(still used in lazy/array/single-value paths). Should we add comment here to keep in sync so duplication doesn't silently drift?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment to explain both why it is there, and that it needs to be kept in sync.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-spanner/google/cloud/spanner_v1/_helpers.py
return operator.attrgetter("bool_value")
elif type_code == TypeCode.INT64:
return _parse_int64
return lambda value_pb: int(value_pb.string_value)

@rahul2393 rahul2393 Jun 4, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment on why only STRING/BOOL use attrgetter(faster) while transform trypes use lambdas?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment to explain.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@olavloite
chore(spanner): address review comments
1c89fac
@olavloite
olavloite merged commit 3f70b2f into main Jun 5, 2026
25 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@olavloite
olavloite deleted the spanner-optimize-decoding branch June 5, 2026 08:52
@sofisl sofisl mentioned this pull request Jun 11, 2026
chore: librarian release pull request: 20260611T192009Z #17432
Merged
sofisl added a commit that referenced this pull request Jun 11, 2026
@sofisl
chore: librarian release pull request: 20260611T192009Z (#17432)
6547012
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v0.19.0
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:234b9d1f2ddb057ed7ac6a38db0bf8163d839c65c6cf88ade52530cddebce59e
<details><summary>gapic-generator: v1.35.0</summary>

##
[v1.35.0](gapic-generator-v1.34.1...gapic-generator-v1.35.0)
(2026-06-11)

### Features

* setup.py matches prerelease versions (#17370)
([25b857e](25b857e1))

### Bug Fixes

* require protobuf 6.33.5 to address CVE-2026-0994 (#17349)
([6642263](66422636))

</details>


<details><summary>google-auth: v2.54.0</summary>

##
[v2.54.0](google-auth-v2.53.0...google-auth-v2.54.0)
(2026-06-11)

### Features

* implement regional access boundary support for standalone JWT and
async service accounts (#17025)
([35af616](35af6168))

### Bug Fixes

* configure mTLS for impersonated credentials (#17404)
([57269d5](57269d56))

* fail-fast on missing ECP config file to avoid 30s hang (#17377)
([e096127](e0961270))

* Rename the &#39;seed&#39; argument for setting an initial regional
access boundary for clarity (#17186)
([e5c8cf9](e5c8cf92))

* update incorrect urls in setup.py to point at monorepo vs splitrepo
(#17237)
([eaed04b](eaed04ba))

</details>


<details><summary>google-cloud-alloydb: v0.11.0</summary>

##
[v0.11.0](google-cloud-alloydb-v0.10.0...google-cloud-alloydb-v0.11.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-biglake: v0.5.0</summary>

##
[v0.5.0](google-cloud-biglake-v0.4.0...google-cloud-biglake-v0.5.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17431)
([2e75c78](2e75c78c))

</details>


<details><summary>google-cloud-ces: v0.7.0</summary>

##
[v0.7.0](google-cloud-ces-v0.6.0...google-cloud-ces-v0.7.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-confidentialcomputing: v0.11.0</summary>

##
[v0.11.0](google-cloud-confidentialcomputing-v0.10.0...google-cloud-confidentialcomputing-v0.11.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-modelarmor: v0.7.0</summary>

##
[v0.7.0](google-cloud-modelarmor-v0.6.0...google-cloud-modelarmor-v0.7.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-network-services: v0.10.0</summary>

##
[v0.10.0](google-cloud-network-services-v0.9.0...google-cloud-network-services-v0.10.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17431)
([2e75c78](2e75c78c))

</details>


<details><summary>google-cloud-oracledatabase: v0.6.0</summary>

##
[v0.6.0](google-cloud-oracledatabase-v0.5.0...google-cloud-oracledatabase-v0.6.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-spanner: v3.68.0</summary>

##
[v3.68.0](google-cloud-spanner-v3.67.0...google-cloud-spanner-v3.68.0)
(2026-06-11)

### Features

* add asynchronous code snippets and minor cleanup changes (#17337)
([d6aaf61](d6aaf610))

### Performance Improvements

* optimize query result decoding (#17375)
([3f70b2f](3f70b2ff))

</details>


<details><summary>google-cloud-storage: v3.12.0</summary>

##
[v3.12.0](google-cloud-storage-v3.11.0...google-cloud-storage-v3.12.0)
(2026-06-11)

### Features

* full object checksum: implement rolling checksum and verification in
reads resumption strategy (#17262)
([2361ba6](2361ba6e))

* Enable full object checksum PR 1/3 : parse finalize_time and server
crc32c in async object stream (#17261)
([72c7a27](72c7a272))

* full object checksum: integrate full-object checksum in
AsyncMultiRangeDownloader (#17263)
([b6a85e4](b6a85e49))

</details>


<details><summary>google-developer-knowledge: v0.1.0</summary>

##
[v0.1.0](google-developer-knowledge-v0.0.0...google-developer-knowledge-v0.1.0)
(2026-06-11)

### Features

* add google-developer-knowledge (#17417)
([ca02afc](ca02afce))

</details>
This was referenced Jun 23, 2026
chore(main): release google-cloud-spanner 0.1.0 #17549
Closed
chore(main): release google-cloud-spanner 0.1.0 #17550
Closed
chalmerlowe pushed a commit that referenced this pull request Jun 25, 2026
@sofisl @chalmerlowe
chore: librarian release pull request: 20260611T192009Z (#17432)
e020cbc
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v0.19.0
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:234b9d1f2ddb057ed7ac6a38db0bf8163d839c65c6cf88ade52530cddebce59e
<details><summary>gapic-generator: v1.35.0</summary>

##
[v1.35.0](gapic-generator-v1.34.1...gapic-generator-v1.35.0)
(2026-06-11)

### Features

* setup.py matches prerelease versions (#17370)
([25b857e](25b857e1))

### Bug Fixes

* require protobuf 6.33.5 to address CVE-2026-0994 (#17349)
([6642263](66422636))

</details>


<details><summary>google-auth: v2.54.0</summary>

##
[v2.54.0](google-auth-v2.53.0...google-auth-v2.54.0)
(2026-06-11)

### Features

* implement regional access boundary support for standalone JWT and
async service accounts (#17025)
([35af616](35af6168))

### Bug Fixes

* configure mTLS for impersonated credentials (#17404)
([57269d5](57269d56))

* fail-fast on missing ECP config file to avoid 30s hang (#17377)
([e096127](e0961270))

* Rename the &#39;seed&#39; argument for setting an initial regional
access boundary for clarity (#17186)
([e5c8cf9](e5c8cf92))

* update incorrect urls in setup.py to point at monorepo vs splitrepo
(#17237)
([eaed04b](eaed04ba))

</details>


<details><summary>google-cloud-alloydb: v0.11.0</summary>

##
[v0.11.0](google-cloud-alloydb-v0.10.0...google-cloud-alloydb-v0.11.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-biglake: v0.5.0</summary>

##
[v0.5.0](google-cloud-biglake-v0.4.0...google-cloud-biglake-v0.5.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17431)
([2e75c78](2e75c78c))

</details>


<details><summary>google-cloud-ces: v0.7.0</summary>

##
[v0.7.0](google-cloud-ces-v0.6.0...google-cloud-ces-v0.7.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-confidentialcomputing: v0.11.0</summary>

##
[v0.11.0](google-cloud-confidentialcomputing-v0.10.0...google-cloud-confidentialcomputing-v0.11.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-modelarmor: v0.7.0</summary>

##
[v0.7.0](google-cloud-modelarmor-v0.6.0...google-cloud-modelarmor-v0.7.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-network-services: v0.10.0</summary>

##
[v0.10.0](google-cloud-network-services-v0.9.0...google-cloud-network-services-v0.10.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17431)
([2e75c78](2e75c78c))

</details>


<details><summary>google-cloud-oracledatabase: v0.6.0</summary>

##
[v0.6.0](google-cloud-oracledatabase-v0.5.0...google-cloud-oracledatabase-v0.6.0)
(2026-06-11)

### Features

* update API sources and regenerate (#17413)
([59fe7cf](59fe7cf8))

</details>


<details><summary>google-cloud-spanner: v3.68.0</summary>

##
[v3.68.0](google-cloud-spanner-v3.67.0...google-cloud-spanner-v3.68.0)
(2026-06-11)

### Features

* add asynchronous code snippets and minor cleanup changes (#17337)
([d6aaf61](d6aaf610))

### Performance Improvements

* optimize query result decoding (#17375)
([3f70b2f](3f70b2ff))

</details>


<details><summary>google-cloud-storage: v3.12.0</summary>

##
[v3.12.0](google-cloud-storage-v3.11.0...google-cloud-storage-v3.12.0)
(2026-06-11)

### Features

* full object checksum: implement rolling checksum and verification in
reads resumption strategy (#17262)
([2361ba6](2361ba6e))

* Enable full object checksum PR 1/3 : parse finalize_time and server
crc32c in async object stream (#17261)
([72c7a27](72c7a272))

* full object checksum: integrate full-object checksum in
AsyncMultiRangeDownloader (#17263)
([b6a85e4](b6a85e49))

</details>


<details><summary>google-developer-knowledge: v0.1.0</summary>

##
[v0.1.0](google-developer-knowledge-v0.0.0...google-developer-knowledge-v0.1.0)
(2026-06-11)

### Features

* add google-developer-knowledge (#17417)
([ca02afc](ca02afce))

</details>
@release-please release-please Bot mentioned this pull request Jul 15, 2026
chore(main): release google-cloud-spanner 0.1.0 #17720
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rahul2393 rahul2393 rahul2393 approved these changes
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@olavloite @rahul2393
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.