-
Notifications
You must be signed in to change notification settings - Fork 645
perf(txindex): search optimization #3458
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
Conversation
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.
Thanks @inon-man ❤️
tagKeySeparator = "/" | ||
tagKeySeparatorRune = '/' | ||
eventSeqSeparator = "$es$" | ||
tagKeySeparator = "/" |
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.
Do we still need this?
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.
I guess it is for conditional search.
Really helpful, thank you! Can we backport this? |
According to our backporting policy, we will only backport bug fixes to v0.38 and v0.37. We can backport to the |
<!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> This PR addresses several optimization points for TxIndex.Search: 1. Remove expensive map access from sorting function 2. Replace sort.Slice to sort.Sort with sorter approach 3. Reduce heap allocations from extractEventSeqFromKey benchstat result: ``` goos: darwin goarch: amd64 pkg: github.com/cometbft/cometbft/state/txindex/kv cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TxSearchBigResult-20 3236.1m ± 7% 945.9m ± 9% -70.77% (p=0.002 n=6) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TxSearchBigResult-20 426.1Mi ± 0% 311.6Mi ± 0% -26.86% (p=0.002 n=6) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TxSearchBigResult-20 4.040M ± 0% 2.040M ± 0% -49.51% (p=0.002 n=6) ``` #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec --------- Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit 95af24d)
This PR addresses several optimization points for TxIndex.Search: 1. Remove expensive map access from sorting function 2. Replace sort.Slice to sort.Sort with sorter approach 3. Reduce heap allocations from extractEventSeqFromKey benchstat result: ``` goos: darwin goarch: amd64 pkg: github.com/cometbft/cometbft/state/txindex/kv cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TxSearchBigResult-20 3236.1m ± 7% 945.9m ± 9% -70.77% (p=0.002 n=6) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TxSearchBigResult-20 426.1Mi ± 0% 311.6Mi ± 0% -26.86% (p=0.002 n=6) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TxSearchBigResult-20 4.040M ± 0% 2.040M ± 0% -49.51% (p=0.002 n=6) ``` #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #3458 done by [Mergify](https://mergify.com). Co-authored-by: inon-man <121477599+inon-man@users.noreply.github.com>
<!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> This PR addresses several optimization points for TxIndex.Search: 1. Remove expensive map access from sorting function 2. Replace sort.Slice to sort.Sort with sorter approach 3. Reduce heap allocations from extractEventSeqFromKey benchstat result: ``` goos: darwin goarch: amd64 pkg: github.com/cometbft/cometbft/state/txindex/kv cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TxSearchBigResult-20 3236.1m ± 7% 945.9m ± 9% -70.77% (p=0.002 n=6) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TxSearchBigResult-20 426.1Mi ± 0% 311.6Mi ± 0% -26.86% (p=0.002 n=6) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TxSearchBigResult-20 4.040M ± 0% 2.040M ± 0% -49.51% (p=0.002 n=6) ``` #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec --------- Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit 95af24d) # Conflicts: # .changelog/v0.38.8/improvements/3458-txindex-search-optimization.md # state/txindex/kv/kv.go # state/txindex/kv/kv_test.go
This PR addresses several optimization points for TxIndex.Search: 1. Remove expensive map access from sorting function 2. Replace sort.Slice to sort.Sort with sorter approach 3. Reduce heap allocations from extractEventSeqFromKey benchstat result: ``` goos: darwin goarch: amd64 pkg: github.com/cometbft/cometbft/state/txindex/kv cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TxSearchBigResult-20 3236.1m ± 7% 945.9m ± 9% -70.77% (p=0.002 n=6) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TxSearchBigResult-20 426.1Mi ± 0% 311.6Mi ± 0% -26.86% (p=0.002 n=6) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TxSearchBigResult-20 4.040M ± 0% 2.040M ± 0% -49.51% (p=0.002 n=6) ``` - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec --------- Co-authored-by: Anton 8000 Kaliaev <anton.kalyaev@gmail.com>
This PR addresses several optimization points for TxIndex.Search: 1. Remove expensive map access from sorting function 2. Replace sort.Slice to sort.Sort with sorter approach 3. Reduce heap allocations from extractEventSeqFromKey benchstat result: ``` goos: darwin goarch: amd64 pkg: github.com/cometbft/cometbft/state/txindex/kv cpu: Intel(R) Core(TM) i9-10910 CPU @ 3.60GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TxSearchBigResult-20 3236.1m ± 7% 945.9m ± 9% -70.77% (p=0.002 n=6) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TxSearchBigResult-20 426.1Mi ± 0% 311.6Mi ± 0% -26.86% (p=0.002 n=6) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TxSearchBigResult-20 4.040M ± 0% 2.040M ± 0% -49.51% (p=0.002 n=6) ``` #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #3458 done by [Mergify](https://mergify.com). Co-authored-by: inon-man <121477599+inon-man@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
This PR addresses several optimization points for TxIndex.Search:
benchstat result:
PR checklist
.changelog
(we use unclog to manage our changelog)docs/
orspec/
) and code comments