-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: store/cachekv: preallocate kvL in dirtyItems which gets appended too #14168
Merged
tac0turtle
merged 2 commits into
main
from
store-cachekv-store-preallocate-kvL-in-dirtyItems
Dec 7, 2022
Merged
perf: store/cachekv: preallocate kvL in dirtyItems which gets appended too #14168
tac0turtle
merged 2 commits into
main
from
store-cachekv-store-preallocate-kvL-in-dirtyItems
Dec 7, 2022
Conversation
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
yihuang
approved these changes
Dec 6, 2022
yihuang
reviewed
Dec 6, 2022
tac0turtle
approved these changes
Dec 6, 2022
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.
makes sense
…d too Noticed in RAM profiles that the append for kvL had a concentrated amount of RAM consumption yet where we invoke make didn't have any capacity. Alas on profiling the results show a distribution which eases on allocation pressure and distributes allocations across different sections: * Before: ```shell . . 342: kvL := make([]*kv.Pair, 0) . . 343: for i := startIndex; i <= endIndex; i++ { . . 344: key := strL[i] . . 345: cacheValue := store.cache[key] 1.14GB 1.14GB 346: kvL = append(kvL, &kv.Pair{Key: []byte(key), Value: cacheValue.value}) . . 347: } ``` * After: ```shell 76.33MB 76.33MB 342: kvL := make([]*kv.Pair, 0, endIndex-startIndex) . . 343: for i := startIndex; i <= endIndex; i++ { . . 344: key := strL[i] . . 345: cacheValue := store.cache[key] 851.42MB 851.42MB 346: kvL = append(kvL, &kv.Pair{Key: []byte(key), Value: cacheValue.value}) . . 347: } ``` which also shows up in benchmark results: ```shell $ benchstat before.txt after.txt name old time/op new time/op delta IteratorOnParentWith1MDeletes-8 1.69s ± 5% 1.65s ± 6% ~ (p=0.095 n=9+10) name old alloc/op new alloc/op delta IteratorOnParentWith1MDeletes-8 238MB ± 0% 214MB ± 0% -9.94% (p=0.000 n=10+9) name old allocs/op new allocs/op delta IteratorOnParentWith1MDeletes-8 3.10M ± 0% 3.10M ± 0% -0.00% (p=0.000 n=10+10) ``` Fixes #14167
odeke-em
force-pushed
the
store-cachekv-store-preallocate-kvL-in-dirtyItems
branch
from
December 6, 2022 22:08
32dbd02
to
1a14565
Compare
[Cosmos SDK] Kudos, SonarCloud Quality Gate passed! |
tac0turtle
added
the
A:automerge
Automatically merge PR once all prerequisites pass.
label
Dec 7, 2022
tac0turtle
deleted the
store-cachekv-store-preallocate-kvL-in-dirtyItems
branch
December 7, 2022 09:00
BrandonWeng
added a commit
to sei-protocol/sei-cosmos
that referenced
this pull request
Dec 15, 2022
## Describe your changes and provide context Cherry picking changes here: * [\#14168](cosmos/cosmos-sdk#14168) perf: store/cachekv: preallocate kvL in dirtyItems which gets appended too * [\#10024](cosmos/cosmos-sdk#10024) fix!: store/cachekv: reduce growth factor for iterator ranging using binary searches #10024 ## Testing performed to validate your change Ran a cluster ![image](https://user-images.githubusercontent.com/18161326/207636380-1c404827-cdb4-4bdc-aade-bfc0294f6cd4.png)
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.
Noticed in RAM profiles that the append for kvL had a concentrated amount of RAM consumption yet where we invoke make didn't have any capacity. Alas on profiling the results show a distribution which eases on allocation pressure and distributes allocations across different sections:
which also shows up in benchmark results:
$ benchstat before.txt after.txt name old time/op new time/op delta IteratorOnParentWith1MDeletes-8 1.69s ± 5% 1.65s ± 6% ~ (p=0.095 n=9+10) name old alloc/op new alloc/op delta IteratorOnParentWith1MDeletes-8 238MB ± 0% 214MB ± 0% -9.94% (p=0.000 n=10+9) name old allocs/op new allocs/op delta IteratorOnParentWith1MDeletes-8 3.10M ± 0% 3.10M ± 0% -0.00% (p=0.000 n=10+10)
Fixes #14167