-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R4R: CacheKVStore keep sorted items #4265
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02eb923
add sortedCache
ca64211
fix ascending
mossid a216e10
fix ascending
mossid c7d6388
rm reverse
mossid 8c5a348
change impl from slice to list
mossid e9d5c08
change to pointer(no performance improvement)
mossid b40f995
fix kvp adding
mossid c1996e0
Add benchmarks
alexanderbez 5d4d5f5
Add pending log entry
alexanderbez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#2286 Improve performance of CacheKVStore iterator. |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cachekv_test | ||
|
||
import ( | ||
"crypto/rand" | ||
"sort" | ||
"testing" | ||
|
||
dbm "github.com/tendermint/tendermint/libs/db" | ||
|
||
"github.com/cosmos/cosmos-sdk/store/cachekv" | ||
"github.com/cosmos/cosmos-sdk/store/dbadapter" | ||
) | ||
|
||
func benchmarkCacheKVStoreIterator(numKVs int, b *testing.B) { | ||
mem := dbadapter.Store{DB: dbm.NewMemDB()} | ||
cstore := cachekv.NewStore(mem) | ||
keys := make([]string, numKVs, numKVs) | ||
|
||
for i := 0; i < numKVs; i++ { | ||
key := make([]byte, 32) | ||
value := make([]byte, 32) | ||
|
||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(value) | ||
|
||
keys[i] = string(key) | ||
cstore.Set(key, value) | ||
} | ||
|
||
sort.Strings(keys) | ||
|
||
for n := 0; n < b.N; n++ { | ||
iter := cstore.Iterator([]byte(keys[0]), []byte(keys[numKVs-1])) | ||
|
||
for _ = iter.Key(); iter.Valid(); iter.Next() { | ||
} | ||
|
||
iter.Close() | ||
} | ||
} | ||
|
||
func BenchmarkCacheKVStoreIterator500(b *testing.B) { benchmarkCacheKVStoreIterator(500, b) } | ||
func BenchmarkCacheKVStoreIterator1000(b *testing.B) { benchmarkCacheKVStoreIterator(1000, b) } | ||
func BenchmarkCacheKVStoreIterator10000(b *testing.B) { benchmarkCacheKVStoreIterator(10000, b) } | ||
func BenchmarkCacheKVStoreIterator50000(b *testing.B) { benchmarkCacheKVStoreIterator(50000, b) } | ||
func BenchmarkCacheKVStoreIterator100000(b *testing.B) { benchmarkCacheKVStoreIterator(100000, b) } |
This file contains 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
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.
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.
wow. good catch.