-
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
perf: optimize iteration on nested cache context #13881
Conversation
8d20392
to
d0aa493
Compare
The test(02) failure seems like a non-deterministic one unrelated to this PR, I see it fail on some main branch commit as well: https://github.com/cosmos/cosmos-sdk/actions/runs/3467563489/jobs/5792555203 |
After this optimization, the cpu profile points to the runtime stuff, I believe it's the go-routine used in memdb's iteration, why do we use a go-routine to iterate a in-memory data structure? |
Closes: cosmos#10310 Solution: - cache the valid status
d0aa493
to
ecf35fd
Compare
ecf35fd
to
e2e0135
Compare
Anther round of benchmark: original
Cache valid status
Use btree directly
|
e2e0135
to
0c60aa1
Compare
There is an issue to introduce and rewrite the memdb in favor of tidwall and to stop using the go go routine. This is for cosmos-db. I think we should put this change there and update the repo to cosmos-db like Jacob has done in a pr that is now unblocked. Would this work? Tidwall has a btreehashmap that is more performant that we may be able to take advantage of as well. |
I see, I guess we can do the first part first, caching the valid status. |
Actually I think it's maybe ok to have a separate implementation in cachekv, considering the importance of cachekv, and it don't need to be thread-safe like the |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #13881 +/- ##
==========================================
+ Coverage 56.25% 56.37% +0.11%
==========================================
Files 667 639 -28
Lines 56576 54995 -1581
==========================================
- Hits 31829 31005 -824
+ Misses 22165 21466 -699
+ Partials 2582 2524 -58
|
take back this, it do need to be thread-safe, I've enabled the lock option. rerun benchmark after recent changes:
|
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.
utACK. thank you for this PR.
@Mergifyio backport release/v0.46.x |
@Mergifyio backport release/v0.47.x |
✅ Backports have been created
|
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Closes #10310 (cherry picked from commit cbee1b3) # Conflicts: # CHANGELOG.md # go.mod # go.sum # simapp/go.mod # simapp/go.sum # store/cachekv/store.go # store/cachekv/store_test.go # tests/go.mod # tests/go.sum
✅ Backports have been created
|
@Mergifyio backport release/v0.45.x |
✅ Backports have been created
|
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Closes #10310 (cherry picked from commit cbee1b3) # Conflicts: # CHANGELOG.md # go.mod # go.sum # simapp/go.mod # simapp/go.sum # store/cachekv/memiterator.go # store/cachekv/store.go # store/cachekv/store_test.go # tests/go.mod # tests/go.sum
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Closes cosmos#10310 (cherry picked from commit cbee1b3)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Closes cosmos#10310
…) (cosmos#14341) Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
Description
Closes: #10310
Solution:
skipUntilExistsOrInvalid
at construction and end ofNext
, cache the valid statusrun benchmark:
go test -run=^$ -bench=. -benchmem ./store/cachekv/benchmark_test.go -count=10
.benchstat compare result:
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change