Skip to content

perf: Micro optimization to save one allocation per packet (backport #3018)#3023

Merged
melekes merged 3 commits intov0.37.xfrom
mergify/bp/v0.37.x/pr-3018
May 7, 2024
Merged

perf: Micro optimization to save one allocation per packet (backport #3018)#3023
melekes merged 3 commits intov0.37.xfrom
mergify/bp/v0.37.x/pr-3018

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented May 7, 2024

This PR is a slight optimization to save one allocation per packet. We have much more worthwhile performance improvements to pursue, just driveby noticed it as I was reading through the code. (Though I am surprised this did add up to 1 second in total -- 4% of the processing time)

This re-uses the byte reader's allocation across all ReadMsg's. There is no concurrenct access possible under safe usage (also implied by the reader)

This is the cause of the 1s time on the far right:
image


PR checklist

  • Tests written/updated - covered by existing tests
  • 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 #3018 done by [Mergify](https://mergify.com).

This PR is a slight optimization to save one allocation per packet. We
have much more worthwhile performance improvements to pursue, just
driveby noticed it as I was reading through the code. (Though I am
surprised this did add up to 1 second in total -- 4% of the processing
time)

This re-uses the byte reader's allocation across all ReadMsg's. There is
no concurrenct access possible under safe usage (also implied by the
reader)

This is the cause of the 1s time on the far right:

![image](https://github.com/cometbft/cometbft/assets/6440154/d6c6bfaa-d287-4355-b094-9bdcbc6379c8)

---

#### PR checklist

- [x] Tests written/updated - covered by existing tests
- [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 6dade2b)
@mergify mergify bot requested a review from a team as a code owner May 7, 2024 06:44
@melekes melekes merged commit 2a7a880 into v0.37.x May 7, 2024
@melekes melekes deleted the mergify/bp/v0.37.x/pr-3018 branch May 7, 2024 07:21
ValarDragon added a commit to osmosis-labs/cometbft that referenced this pull request May 25, 2024
…ometbft#3018) (cometbft#3023)

This PR is a slight optimization to save one allocation per packet. We
have much more worthwhile performance improvements to pursue, just
driveby noticed it as I was reading through the code. (Though I am
surprised this did add up to 1 second in total -- 4% of the processing
time)

This re-uses the byte reader's allocation across all ReadMsg's. There is
no concurrenct access possible under safe usage (also implied by the
reader)

This is the cause of the 1s time on the far right: 

![image](https://github.com/cometbft/cometbft/assets/6440154/d6c6bfaa-d287-4355-b094-9bdcbc6379c8)


---

#### PR checklist

- [x] Tests written/updated - covered by existing tests
- [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#3018 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>
mergify bot added a commit to osmosis-labs/cometbft that referenced this pull request May 28, 2024
…ometbft#3018) (cometbft#3023)

This PR is a slight optimization to save one allocation per packet. We
have much more worthwhile performance improvements to pursue, just
driveby noticed it as I was reading through the code. (Though I am
surprised this did add up to 1 second in total -- 4% of the processing
time)

This re-uses the byte reader's allocation across all ReadMsg's. There is
no concurrenct access possible under safe usage (also implied by the
reader)

This is the cause of the 1s time on the far right:

![image](https://github.com/cometbft/cometbft/assets/6440154/d6c6bfaa-d287-4355-b094-9bdcbc6379c8)

---

#### PR checklist

- [x] Tests written/updated - covered by existing tests
- [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#3018 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>
(cherry picked from commit ad8f851)
PaddyMc added a commit to osmosis-labs/cometbft that referenced this pull request May 28, 2024
…… (backport #75) (#80)

* perf: Micro optimization to save one allocation per packet (backport cometbft#3018) (cometbft#3023)

This PR is a slight optimization to save one allocation per packet. We
have much more worthwhile performance improvements to pursue, just
driveby noticed it as I was reading through the code. (Though I am
surprised this did add up to 1 second in total -- 4% of the processing
time)

This re-uses the byte reader's allocation across all ReadMsg's. There is
no concurrenct access possible under safe usage (also implied by the
reader)

This is the cause of the 1s time on the far right:

![image](https://github.com/cometbft/cometbft/assets/6440154/d6c6bfaa-d287-4355-b094-9bdcbc6379c8)

---

#### PR checklist

- [x] Tests written/updated - covered by existing tests
- [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#3018 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>
(cherry picked from commit ad8f851)

* changelog

(cherry picked from commit dd19cb0)

# Conflicts:
#	CHANGELOG.md

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
Co-authored-by: PaddyMc <paddymchale@hotmail.com>
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