-
Notifications
You must be signed in to change notification settings - Fork 637
mempool: LRUTxCache.Reset could benefit from using the map clearing idiom to reduce CPU & RAM pressure #2243
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
Milestone
Comments
https://tip.golang.org/ref/spec#Clear
|
melekes
added a commit
that referenced
this issue
Feb 7, 2024
instead of allocating a new one Closes #2243
4 tasks
@melekes clear was introduced in Go1.21, is every user of this repository already upgraded to that very recent Go version? |
https://github.com/cometbft/cometbft?tab=readme-ov-file#minimum-requirements don't know about every user, but our current min version is 1.21 as stated in the README |
github-merge-queue bot
pushed a commit
that referenced
this issue
Feb 9, 2024
instead of allocating a new one Closes #2243 It should not be backported onto <= v0.37 because their min Go version is 1.20, and `clear` was introduced in Go 1.21. --- #### PR checklist - [ ] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
mergify bot
pushed a commit
that referenced
this issue
Feb 9, 2024
instead of allocating a new one Closes #2243 It should not be backported onto <= v0.37 because their min Go version is 1.20, and `clear` was introduced in Go 1.21. --- #### PR checklist - [ ] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] 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 fc4e1ef)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If we look at this code
cometbft/mempool/cache.go
Lines 56 to 62 in f92bace
we can see that .Reset simply takes a lock then allocates a fresh map by discarding the previous one.
Suggestion
We can reduce on CPU & RAM pressure by using the map clearing idiom aka
which in performance wisdom is a known and accepted Go idiom for reducing CPU & RAM pressure by reusing the map.
The text was updated successfully, but these errors were encountered: