perf: O(1) readset dedup in OCC multiversion store#3245
Draft
perf: O(1) readset dedup in OCC multiversion store#3245
Conversation
Add a parallel dedup index (map[string]map[string]struct{}) alongside
the existing readset slice to replace O(n) linear scan + bytes.Equal
with O(1) map lookup when checking for duplicate values in
UpdateReadSet. The ReadSet type and all consumers (validation,
SetReadset, iterators) are unchanged — only the dedup check is faster.
This matters for iterator-heavy workloads where the same keys are
scanned multiple times within a single transaction, causing repeated
UpdateReadSet calls with identical values.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3245 +/- ##
=======================================
Coverage 59.26% 59.26%
=======================================
Files 2070 2070
Lines 169788 169791 +3
=======================================
+ Hits 100631 100634 +3
Misses 60358 60358
Partials 8799 8799
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Summary
UpdateReadSetin the OCC multiversion store (VersionIndexedStore) previously used a linear scan withbytes.Equalto deduplicate values per keyreadsetDedupindex (map[string]map[string]struct{}) for O(1) dedup lookupsReadSettype and all consumers (validation,SetReadset, iterators) are unchanged — only the internal dedup path is fasterMotivation
UpdateReadSetis called on every storage read in every parallel transaction. For iterator-heavy workloads (range scans over storage, e.g., DEX order books, token holder lists), the same keys are visited multiple times within a single tx, triggering the dedup check each time. The previous O(n) scan withbytes.Equalcompounded across many reads. OCC is enabled by default on all Sei validators (occ-enabled = true).Design
Rather than changing the
ReadSettype (which would ripple across the codebase), we keep the existing[][]byteslice for the public interface and add a privatemap[string]struct{}set per key as a shadow index. Both are updated together inUpdateReadSet. The dedup check hits the map (O(1)), while validation andSetReadsetcontinue to read from the slice.Test plan
go test ./sei-cosmos/store/multiversion/)gofmt -s -lcleango buildclean🤖 Generated with Claude Code