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

dev: swap_remove #11405

Merged
merged 2 commits into from
Oct 2, 2024
Merged

dev: swap_remove #11405

merged 2 commits into from
Oct 2, 2024

Conversation

greged93
Copy link
Contributor

@greged93 greged93 commented Oct 2, 2024

Replaces remove with swap_remove for optimized removal of items in a Vec where preservation of order of the items isn't needed.

@greged93
Copy link
Contributor Author

greged93 commented Oct 2, 2024

should we pin clippy for the bins to nightly-2024-09-25?

@fgimenez
Copy link
Member

fgimenez commented Oct 2, 2024

should we pin clippy for the bins to nightly-2024-09-25?

yep, done here #11401

@@ -106,7 +106,7 @@ where
/// # Panics
/// If the index is out of bounds.
pub fn remove_peer(&mut self, index: usize) -> Peer<C, Pool> {
self.peers.remove(index)
self.peers.swap_remove(index)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this we can't do because this messes with the ordering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh ok, didn't know peers ordering was important, will revert

@@ -383,7 +383,7 @@ where
.into())
}

let sealed_target = headers.remove(0).seal_slow();
let sealed_target = headers.swap_remove(0).seal_slow();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is fine because we only need the first one and aren't using it anymore

@@ -303,7 +303,7 @@ where
let (fut, keep_alive) = self.payload_jobs[job].0.resolve();

if keep_alive == KeepPayloadJobAlive::No {
let (_, id) = self.payload_jobs.remove(job);
let (_, id) = self.payload_jobs.swap_remove(job);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is also fine because we always find the index first and the ordering doesn't matter

@mattsse mattsse added the C-perf A change motivated by improving speed, memory usage or disk footprint label Oct 2, 2024
@mattsse mattsse added this pull request to the merge queue Oct 2, 2024
Merged via the queue into paradigmxyz:main with commit d47904f Oct 2, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants