Skip to content

perf(semantic): use swap_remove instead of into_iter().next() in into_root#17183

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root
Dec 22, 2025
Merged

perf(semantic): use swap_remove instead of into_iter().next() in into_root#17183
graphite-app[bot] merged 1 commit intomainfrom
c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Dec 20, 2025

No description provided.

@github-actions github-actions bot added A-semantic Area - Semantic C-performance Category - Solution not expected to change functional behavior, only performance labels Dec 20, 2025
Copy link
Contributor Author

camc314 commented Dec 20, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 20, 2025

CodSpeed Performance Report

Merging #17183 will not alter performance

Comparing c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root (ff2620d) with c/12-20-perf_semantic_use_split_at_mut_instead_of_iterator_in_current_and_parent_mut (18ed7de)

Summary

✅ 42 untouched
⏩ 3 skipped1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 marked this pull request as ready for review December 20, 2025 15:43
@camc314 camc314 requested a review from Dunqing as a code owner December 20, 2025 15:43
@camc314
Copy link
Contributor Author

camc314 commented Dec 20, 2025

This is only called 1x so probably no meaningful perf difference

@overlookmotel
Copy link
Member

overlookmotel commented Dec 21, 2025

I'm very surprised this is any more performant. Creating a slice iterator is extremely cheap (like 1 operation), and in this case even that 1 op should be removed due to the unchecked assertion.

swap_remove is a more complex operation.

What makes you think this is faster? Do you have a demonstration that it is?

Maybe something has changed with the effectiveness of unchecked assertions. If so it'd be good to find out!

@camc314
Copy link
Contributor Author

camc314 commented Dec 21, 2025

I'm very surprised this is any more performant. Creating a slice iterator is extremely cheap (like 1 operation), and in this case even that 1 op should be removed due to the unchecked assertion.

swap_remove is a more complex operation.

What makes you think this is faster? Do you have a demonstration that it is?

Maybe something has changed with the effectiveness of unchecked assertions. If so it'd be good to find out!

I fear something has changed in more recent rust versions, because that's not the behaviour I see:

https://godbolt.org/z/zrs81Gbns

using swap_remove is ~57 lines of assembluy (no panic calls), whereas the previous is ~141 and a panic call.

For the iterator case, the assert_unchecked assertion doesn't seem to do anything

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 22, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 22, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the c/12-20-perf_semantic_use_split_at_mut_instead_of_iterator_in_current_and_parent_mut branch from 18ed7de to 315c9ed Compare December 22, 2025 13:50
@graphite-app graphite-app bot force-pushed the c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root branch from ff2620d to 605a290 Compare December 22, 2025 13:50
Base automatically changed from c/12-20-perf_semantic_use_split_at_mut_instead_of_iterator_in_current_and_parent_mut to main December 22, 2025 13:56
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 22, 2025
@graphite-app graphite-app bot merged commit 605a290 into main Dec 22, 2025
21 checks passed
@graphite-app graphite-app bot deleted the c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root branch December 22, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants