-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Removed use of iteration through a HashMap/HashSet in rustc_incremental and replaced with IndexMap/IndexSet #110040
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @lcnr (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Aah it appears some tests are failing, ig I didn't hit all the test cases on my local machine while testing (more specifically, the cranelift and gcc backend). I'll make a few edits, then retry tomorrow |
This comment has been minimized.
This comment has been minimized.
Note that (I'm not saying this PR is necessarily a problem in that way, just noting it for caution.) |
Aah, I see. After I fix the issue with cranelift build failing, I'll go investigate that, and keep it in mind for future changes as well :) |
Also just a quick question - I failed the build test for codegen_cranelift and codegen_gcc because the tests I was doing on my local machine never hit those modules. Is there a way I can test those as well? For codegen_cranelift, I found using --target=i686-pc-windows-gnu worked, but is there an equivalent target I can use to make sure my code doesn't break codegen_gcc? Thanks! |
|
ohhhh I see, I haven't really been using ./x.py check... maybe I should start doing so, my |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 916c1ca501f3e134b8cd8e61201d5a01a9b19d12 with merge e709771db4bde2ba3203fc1eb0b315b71b35c8c6... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (e709771db4bde2ba3203fc1eb0b315b71b35c8c6): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
with rust-lang/compiler-team#533 we should be able to instead use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/unord/struct.UnordMap.html for a lot of these i think? 🤔 not sure what's the current status here but it feels preferable to use these whenever possible, cc @michaelwoerister |
Ooo, that's a pretty cool data structure, didn't know that existed! Yeah, I guess that provides an even better determinism guarantee than FxIndexMap, because we either have to work with it in an order-agnostic way, or sort it. IDK if it'll cause performance regressions from extra .sorts() (in places where iteration by Fn instead of FnMut isn't sufficient), but I'll be happy to migrate over (whenever possible) and run those performance tests if michaelwoerister confirms that it's indeed the best practice :) |
IndexMap and UnordMap can both make things deterministic but have slightly different properties:
I've been trying to use UnordMap where possible because it is a bit more robust (i.e. it introduces a kind of indeterminism firewall). But for maps where it's trivially obvious that they are built deterministically, IndexMap is a good choice too. |
Alright, will do 👍 |
This comment has been minimized.
This comment has been minimized.
69ba7dc
to
f5f638c
Compare
@rustbot label -S-waiting-on-author +S-waiting-on-review |
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.
I have to admit that the bool
argument to into_sorted_stable_ord
is very confusing to me and even after looking it up in the documentation I always have to wait a second and think about whether it is correct.
I would like us to either add a const CAN_USE_UNSTABLE_SORT: bool
to StableOrd
or alternatively always use a stable sort and only add unstable sorting where it is actually performance critical.
Please either do that in this PR or I will open a github issue once your PR lands.
Other thoughts: UnordItems
using into()
via From
instead of having a method called collect
is also confusing imo.
after dealing with review comments:
r=me,michaelwoerister
.items() | ||
.map(|(_, path)| path.as_str()) | ||
.into_sorted_stable_ord(false) |
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.
&String
should implement StableOrd
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.
Hmm, apparently not. Would it be correct to impl StableOrd for &T
if T
is StableOrd? I believe it should, but just checking in (if not, then I'll just add the impl for &String
on its own)
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.
Would it be correct to impl StableOrd for &T if T is StableOrd?
yes
@lcnr, that sounds like a great idea! If you open an issue, feel free to assign it to me. |
… few misc issues, added collect to UnordItems
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
…fixed a few misc issues, added collect to UnordItems
Alright, I applied the review suggestions and switched UnordItems::into_sorted_stable_ord to use CAN_USE_UNSTABLE_SORT, and added collect to UnordItems @rustbot label -S-waiting-on-author +S-waiting-on-review |
This comment has been minimized.
This comment has been minimized.
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.
a few nits for code which can be cleaned up now. Feel free to do them in a separate PR once this has landed
☀️ Test successful - checks-actions |
Finished benchmarking commit (a0df04c): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 647.603s -> 648.385s (0.12%) |
…compiler-errors Removed unnecessary &String -> &str, now that &String implements StableOrd as well Applied a few nits suggested by lcnr to PR rust-lang#110040 (nits can be found [here](rust-lang#110040 (review)).) Making a new PR because the old one was already merged, and given that this just applies changes that were already suggested, reviewing it should be fairly open-and-shut.
This allows for the
#[allow(rustc::potential_query_instability)]
in rustc_incremental to be removed, moving towards fixing #84447 (although a LOT more modules have to be changed to fully resolve it). Only HashMaps/HashSets that are being iterated through have been modified (although many structs and traits outside of rustc_incremental had to be modified as well, as they had fields/methods that involved a HashMap/HashSet that would be iterated through)I'm making a PR for just 1 module changed to test for performance regressions and such, for future changes I'll either edit this PR to reflect additional modules being converted, or batch multiple modules of changes together and make a PR for each group of modules.