Skip to content

perf(txindex): search optimization (backport #3458)#3464

Merged
melekes merged 1 commit intov1.xfrom
mergify/bp/v1.x/pr-3458
Jul 10, 2024
Merged

perf(txindex): search optimization (backport #3458)#3464
melekes merged 1 commit intov1.xfrom
mergify/bp/v1.x/pr-3458

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Jul 10, 2024

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

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments
  • Title follows the Conventional Commits spec

This is an automatic backport of pull request #3458 done by [Mergify](https://mergify.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)
@mergify mergify bot requested a review from a team as a code owner July 10, 2024 06:08
@mergify mergify bot requested a review from a team July 10, 2024 06:08
@melekes melekes merged commit 36af45f into v1.x Jul 10, 2024
@melekes melekes deleted the mergify/bp/v1.x/pr-3458 branch July 10, 2024 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants