Skip to content
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

perf(p2p): Remove unnecessary atomic read #2950

Merged
merged 1 commit into from
May 2, 2024

Conversation

ValarDragon
Copy link
Collaborator

@ValarDragon ValarDragon commented Apr 30, 2024

This PR is a driveby change. We were doing an atomic read here, but this is unnecessary. Nothing in the codebase modified this variable after instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt like a minor code nit

@ValarDragon ValarDragon requested review from a team as code owners April 30, 2024 19:44
@ValarDragon ValarDragon changed the title Remove unnecessary atomic read perf(p2p): Remove unnecessary atomic read Apr 30, 2024
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ValarDragon ❤️

@melekes melekes added backport-to-v0.37.x Tell Mergify to backport the PR to v0.37.x backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x backport-to-v1.x Tell Mergify to backport the PR to v1.x labels May 1, 2024
@melekes melekes added this pull request to the merge queue May 2, 2024
Merged via the queue into cometbft:main with commit 9ae5886 May 2, 2024
38 checks passed
mergify bot pushed a commit that referenced this pull request May 2, 2024
This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit

(cherry picked from commit 9ae5886)
mergify bot pushed a commit that referenced this pull request May 2, 2024
This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit

(cherry picked from commit 9ae5886)
mergify bot pushed a commit that referenced this pull request May 2, 2024
This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit

(cherry picked from commit 9ae5886)
melekes pushed a commit that referenced this pull request May 2, 2024
This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
#2950 done by [Mergify](https://mergify.com).

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
melekes pushed a commit that referenced this pull request May 2, 2024
This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
#2950 done by [Mergify](https://mergify.com).

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
melekes pushed a commit that referenced this pull request May 2, 2024
This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
#2950 done by [Mergify](https://mergify.com).

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
czarcas7ic pushed a commit to osmosis-labs/cometbft that referenced this pull request May 2, 2024
…ometbft#2972)

This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
cometbft#2950 done by [Mergify](https://mergify.com).

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
czarcas7ic added a commit to osmosis-labs/cometbft that referenced this pull request May 3, 2024
…ometbft#2972) (#41)

This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
cometbft#2950 done by [Mergify](https://mergify.com).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
mergify bot pushed a commit to osmosis-labs/cometbft that referenced this pull request May 3, 2024
…ometbft#2972) (#41)

This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
cometbft#2950 done by [Mergify](https://mergify.com).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
(cherry picked from commit c1cebed)
mergify bot pushed a commit to osmosis-labs/cometbft that referenced this pull request May 3, 2024
…ometbft#2972) (#41)

This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
cometbft#2950 done by [Mergify](https://mergify.com).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
(cherry picked from commit c1cebed)
czarcas7ic added a commit to osmosis-labs/cometbft that referenced this pull request May 3, 2024
…ometbft#2972) (#41) (#50)

This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
cometbft#2950 done by [Mergify](https://mergify.com).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
(cherry picked from commit c1cebed)

Co-authored-by: Adam Tucker <adam@osmosis.team>
czarcas7ic added a commit to osmosis-labs/cometbft that referenced this pull request May 3, 2024
…ometbft#2972) (#41) (#51)

This PR is a driveby change. We were doing an atomic read here, but this
is unnecessary. Nothing in the codebase modified this variable after
instantiation.

Doesn't really feel changelog worthy, but I can add one if we want. Felt
like a minor code nit<hr>This is an automatic backport of pull request
cometbft#2950 done by [Mergify](https://mergify.com).

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
(cherry picked from commit c1cebed)

Co-authored-by: Adam Tucker <adam@osmosis.team>
@sergio-mena
Copy link
Contributor

sergio-mena commented May 3, 2024

Hi, getting here a bit late...

I've checked the call hierarchy of sendSomePacketMsgs and I see that, ultimately, it's being called from two different goroutines (potentially for the same MConnection):

  • It's called from MConnection.FlushStop <-- pex.Reactor.Receive (actually, an ad-hoc goroutine there)
  • It's called from MConnection.sendRoutine, which is run as a goroutine

In principle, we could suspect there might be a race between FlushStop and sendRoutine. However, FlushStop waits on channel MConnection.doneSendRoutine before calling sendSomePacketMsgs, so we should be good.

Posting this here to further document this change.

@cason
Copy link
Contributor

cason commented May 8, 2024

Just for context, calling FlushStop more than once is not a problem. The method startswith a call to stopServices. This method is protected by a lock and once the first execution of this method completes, all the following will return true. When this method returns true, the FlushStop method is a no-op.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-v0.37.x Tell Mergify to backport the PR to v0.37.x backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x backport-to-v1.x Tell Mergify to backport the PR to v1.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants