perf(txindex): Lower allocation overhead of txIndex matchRange#2839
Merged
melekes merged 3 commits intocometbft:mainfrom Apr 24, 2024
Merged
Conversation
melekes
approved these changes
Apr 18, 2024
| LOOP: | ||
| for ; it.Valid(); it.Next() { | ||
| if !isTagKey(it.Key()) { | ||
| // TODO: We need to make a function for getting it.Key() as a byte slice with no copies. |
Collaborator
There was a problem hiding this comment.
Would you mind opening an issue for this?
Contributor
Author
There was a problem hiding this comment.
Sure! Do you want me to delete the comment as well?
Contributor
Author
There was a problem hiding this comment.
cometbft-db issue opened: cometbft/cometbft-db#156
Collaborator
There was a problem hiding this comment.
Sure! Do you want me to delete the comment as well?
no
Contributor
Author
cason
approved these changes
Apr 23, 2024
cason
left a comment
There was a problem hiding this comment.
Thanks for this.
I couldn't find (no test performed, only by reading) operational differences, while the changes probably reduce the memory footprint.
| return 0, errors.New("second last separator not found") | ||
| } | ||
|
|
||
| return strconv.ParseInt(parts[len(parts)-2], 10, 64) |
mergify bot
pushed a commit
that referenced
this pull request
Apr 24, 2024
In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- #### PR checklist - [x] Tests written/updated - All existing tests still apply - [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 (cherry picked from commit e75267f)
4 tasks
mergify bot
pushed a commit
that referenced
this pull request
Apr 24, 2024
In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- #### PR checklist - [x] Tests written/updated - All existing tests still apply - [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 (cherry picked from commit e75267f) # Conflicts: # state/txindex/kv/kv.go
mergify bot
pushed a commit
that referenced
this pull request
Apr 24, 2024
In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- #### PR checklist - [x] Tests written/updated - All existing tests still apply - [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 (cherry picked from commit e75267f) # Conflicts: # .changelog/v0.37.5/improvements/2839-tx_index-lower-heap-allocation.md # state/txindex/kv/kv.go
This was referenced Apr 24, 2024
melekes
pushed a commit
that referenced
this pull request
Apr 24, 2024
…ort #2839) (#2882) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- #### PR checklist - [x] Tests written/updated - All existing tests still apply - [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 #2839 done by [Mergify](https://mergify.com). Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
melekes
added a commit
that referenced
this pull request
Apr 24, 2024
…ort #2839) (#2883) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- #### PR checklist - [x] Tests written/updated - All existing tests still apply - [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 #2839 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
melekes
added a commit
that referenced
this pull request
Apr 24, 2024
…ort #2839) (#2884) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- #### PR checklist - [x] Tests written/updated - All existing tests still apply - [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 #2839 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
czarcas7ic
pushed a commit
to osmosis-labs/cometbft
that referenced
this pull request
Apr 29, 2024
…ort cometbft#2839) (cometbft#2884) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- - [x] Tests written/updated - All existing tests still apply - [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 cometbft#2839 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Merged
7 tasks
czarcas7ic
added a commit
to osmosis-labs/cometbft
that referenced
this pull request
Apr 30, 2024
#27) * perf(txindex): Lower allocation overhead of txIndex matchRange (backport cometbft#2839) (cometbft#2884) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- - [x] Tests written/updated - All existing tests still apply - [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 cometbft#2839 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * add changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
mergify bot
added a commit
to osmosis-labs/cometbft
that referenced
this pull request
Apr 30, 2024
#27) * perf(txindex): Lower allocation overhead of txIndex matchRange (backport cometbft#2839) (cometbft#2884) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- - [x] Tests written/updated - All existing tests still apply - [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 cometbft#2839 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * add changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit efd1ea2)
7 tasks
czarcas7ic
added a commit
to osmosis-labs/cometbft
that referenced
this pull request
Apr 30, 2024
#27) (#31) * perf(txindex): Lower allocation overhead of txIndex matchRange (backport cometbft#2839) (cometbft#2884) In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- - [x] Tests written/updated - All existing tests still apply - [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 cometbft#2839 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * add changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit efd1ea2) Co-authored-by: Adam Tucker <adam@osmosis.team>
3 tasks
mattac21
pushed a commit
that referenced
this pull request
Sep 5, 2025
In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)  This PR is expected to fully compatibly drop this down by a factor of 3. It: - Does not get Key() twice (160GB allocation saved) - Uses no heap allocations for isTagKey (120GB saved) - Does not string cast or do strings.Split in parsing the value (~400GB expected saved) - Reuses the big.Int (24GB saved) The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR. --- - [x] Tests written/updated - All existing tests still apply - [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
This file contains hidden or 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
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.

In Osmosis we see massive amounts of heap pressure/allocations coming from txIndex matchRange. (Screenshot below from ~1 hour of heap profiling)
This PR is expected to fully compatibly drop this down by a factor of 3. It:
The remaining RAM overhead from .Key() needs a cometbft-db API change. The remaining RAM overhead from extracting the value can be saved with an unsafe call for casting the output to string with no heap allocation, but we can do that in a separate PR.
PR checklist
.changelog(we use unclog to manage our changelog)docs/orspec/) and code comments