Conversation
…napshots Single-use snapshots (multi_use=False) are thread-confined and execute at most a single read or query operation. Previously, _SnapshotBase unconditionally instantiated both a Lock and an Event, and acquired locks during inline begin operations even when multi-use was not enabled. This change optimizes single-use snapshots: - Only allocate self._lock and self._transaction_begin_event when multi_use=True. - For single-use snapshots, prevent sequential re-use in _wait_for_transaction_begin() via lightweight flag checks without lock synchronization. - Skip lock acquisition in inline begin and precommit token updates when self._lock is None. - Explicitly pass multi_use=True in Transaction.__init__ to ensure transactions retain lock synchronization. - Document concurrency semantics: single-use snapshots are thread-confined, while multi-use snapshots/transactions synchronize concurrent access.
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes single-use snapshots by avoiding the allocation of locks and events since they are thread-confined and do not run concurrently. The multi_use parameter is now passed to the base snapshot constructor, and lock-dependent methods have been updated to safely handle None values. Comprehensive unit tests have been added to verify this new behavior. I have no feedback to provide as the changes are correct and well-tested.
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.
Single-use snapshots (multi_use=False) are thread-confined and execute at most a single read or query operation. Previously, _SnapshotBase unconditionally instantiated both a Lock and an Event, and acquired locks during inline begin operations even when multi-use was not enabled.
This change optimizes single-use snapshots: