perf(tm2/bptree): find the oldest and newest version with two seeks#5979
Open
davd-gzl wants to merge 8 commits into
Open
perf(tm2/bptree): find the oldest and newest version with two seeks#5979davd-gzl wants to merge 8 commits into
davd-gzl wants to merge 8 commits into
Conversation
discoverVersions scanned every PrefixRoot key to take the min and max version. MutableTree.Load calls it, and the rootmulti immutable store opens a tree per ABCI query at a height, so every custom query reran the full scan. The cost is linear in the retained-version count, and the gno.land default prune strategy keeps 705,600. Root keys are PrefixRoot-version-BE, so key order is version order: the first forward key is the smallest version and the first reverse key is the largest. Seek both ends instead. rootDBKey is the only writer under PrefixRoot and always emits 9 bytes, so the result matches the old scan for every reachable input.
Collaborator
🛠 PR Checks Summary🔴 Pending initial approval by a review team member, or review from tech-staff Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
The comment justified leaving these snapshots unprotected by saying prune and queries are serialized by the ABCI mutex. They are not: the query connection has its own mutex in proxy/client.go, separate from the one consensus and mempool share, so the two genuinely run concurrently. The code is safe for different reasons, and those are the ones a future maintainer needs when deciding whether a new snapshot path can skip reader registration: a query never touches the consensus tree, because rootmulti builds a separate store with its own reader map, and the snapshot registers no reader so it cannot block prune.
Replaces the prose describing the key layout with the layout itself and the value each direction returns.
This reverts commit 67830f9.
davd-gzl
marked this pull request as ready for review
July 21, 2026 14:04
….com/davd-gzl/gno into fix/bptree-bounded-version-discovery
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.
Follow-up to #5937.
Opening the store reads every stored version to find just the oldest and the newest. gno.land keeps 705,600 of them, and every query at a height pays for it.
Version keys are already sorted:
Rfollowed by the version as 8 bytes, biggest part first.Before, per query:
After:
The values were always at the ends; the scan just never looked there. A new test covers the case where pruning removes the oldest versions, so the first key is no longer version 1.
Opening the store this way can also write to the database, since loading rebuilds a stale lookup index. Left for a follow-up, written up in the ADR: skipping the rebuild alone is unsafe, because a read trusts an index entry on its version alone and a stale index would return wrong values.