Repository navigation
perf(bigtable): resolve O(n^2) performance bottleneck in ReadRowsQuery.add_range - #18705
Closed
sahananshylaja-glitch wants to merge 1 commit into
Closed
sahananshylaja-glitch wants to merge 1 commit into
sahananshylaja-glitch wants to merge 1 commit into
Conversation
Fixes O(n^2) performance bottleneck in ReadRowsQuery.add_range. Previously, add_range checked for duplicate ranges by calling self.row_ranges, which dynamically reconstructed Python RowRange wrappers for the entire query on every insert. This caused severe quadratic CPU scaling (e.g., 8,000 ranges took ~400s). This CL optimizes the deduplication by maintaining a Python set of string signatures for O(1) lookups. This restores performant insertion (~0.14s for 8k ranges) while perfectly preserving the deduplication behavior expected by the shard() method.
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes the add_range method in read_rows_query.py by introducing a set of signatures (_range_signatures) to avoid O(n^2) wrapper reconstruction during deduplication. The reviewer suggested a more efficient implementation that uses the serialized byte representation (SerializeToString()) of the underlying protobuf messages as signatures, which avoids string formatting and accessing private attributes like _pb.
Author
|
Closing in favor of PR #18706 authored by the core maintainers based on offline feedback. Thank you |
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.
Fixes O(n^2) performance bottleneck in ReadRowsQuery.add_range.
Linking b/573522284
Previously, add_range checked for duplicate ranges by calling self.row_ranges, which dynamically reconstructed Python RowRange wrappers for the entire query on every insert. This caused severe quadratic CPU scaling (e.g., 8,000 ranges took ~400s).
This CL optimizes the deduplication by maintaining a Python set of string signatures for O(1) lookups. This restores performant insertion (~0.14s for 8k ranges) while perfectly preserving the deduplication behavior expected by the shard() method.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #18196 🦕