-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Mono item collection microoptimizations #162480
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,6 +216,7 @@ where | |
|
|
||
| let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx); | ||
| let cgu_name_cache = &mut UnordMap::default(); | ||
| let mut reachable_inlined_items = FxIndexSet::default(); | ||
|
|
||
| for mono_item in mono_items { | ||
| // Handle only root (GloballyShared) items directly here. Inlined (LocalCopy) items | ||
|
|
@@ -264,15 +265,15 @@ where | |
| // going via another root item. This includes drop-glue, functions from | ||
| // external crates, and local functions the definition of which is | ||
| // marked with `#[inline]`. | ||
| let mut reachable_inlined_items = FxIndexSet::default(); | ||
| reachable_inlined_items.clear(); | ||
| get_reachable_inlined_items(cx.tcx, mono_item, cx.usage_map, &mut reachable_inlined_items); | ||
|
|
||
| // Add those inlined items. It's possible an inlined item is reachable | ||
| // from multiple root items within a CGU, which is fine, it just means | ||
| // the `insert` will be a no-op. | ||
| for inlined_item in reachable_inlined_items { | ||
| for inlined_item in &reachable_inlined_items { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative which might be slightly nicer as it doesn't need a copy: The current implementation is also fine by me tho, if you prefer it. I think both of our options should be identical for performance
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that iter + clear is generally faster than drain, because the implementation of drain tends to be complicated. |
||
| // This is a CGU-private copy. | ||
| cgu.items_mut().entry(inlined_item).or_insert_with(|| MonoItemData { | ||
| cgu.items_mut().entry(*inlined_item).or_insert_with(|| MonoItemData { | ||
| inlined: true, | ||
| linkage: Linkage::Internal, | ||
| visibility: Visibility::Default, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of reserving outside of the
extendcall which is easily forgotten, how about this implementation:#162495
View changes since the review