Skip to content

dev: swap_remove#11405

Merged
mattsse merged 2 commits intoparadigmxyz:mainfrom
greged93:dev/swap-remove
Oct 2, 2024
Merged

dev: swap_remove#11405
mattsse merged 2 commits intoparadigmxyz:mainfrom
greged93:dev/swap-remove

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

/// 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

}

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


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
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