-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Remove attribute_cache from CrateMetadata #50528
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Remove attribute_cache from CrateMetadata This PR will fix #50508 by removing the `attribute_cache` from the `CrateMetadata` struct. Seeing as performance was referenced in the original issue, I also cleaned up a `self.entry(node_id);` call which might have occasionally happened redundantly. r? @michaelwoerister
☀️ Test successful - status-travis |
@Mark-Simulacrum, could we get a perf run please? |
Perf queued. |
Huh, this seems to affect performance quite a bit. Good thing we checked! |
Taking a closer look though, it doesn't seem so bad. The benchmarks affected most are small crates and they regress by 0.01 - 0.02 seconds, which is well below our measurement accuracy. |
First of all, ignore the style-servo numbers. The "clean-incremental" job for that has enormous variance, unfortunately. For the other benchmarks, however, instruction counts have low variance and are reliable. The regressions are mostly in smaller benchmarks, as you say. But the regressions are sizeable, and the affect both non-incremental and incremental builds. I've been landing a lot of speed-ups that are much smaller than this. So a regression of this size doesn't please me, alas :( |
Let's look into how we can get the performance back without having the cache then. I think these are the main offenders: rust/src/librustc_metadata/cstore.rs Lines 186 to 227 in 8ff4b42
|
@whitfin, would you be willing to update your PR to optimize the above methods (the ones that call
This way, we only decode and search the crate attributes once. |
@michaelwoerister I can definitely take a shot at doing so! I'll take a look today at some point & I'll get back to you if I need any further pointers. |
Great, thanks! |
@michaelwoerister ok; should have something to push up shortly. One minor thing though - if I'm adding booleans to With duplicating the entry logic inside rust/src/librustc_metadata/decoder.rs Lines 164 to 166 in 8ff4b42
Do you have any ideas how to work around it? My current approach is to set up the attributes inside the Edit: Ok, I pushed up some working changes for this. It's not particularly clean because of having to decode using the |
Good idea! You can also make them
Yeah, it feels a bit messy to call methods on a potentially only partially initialized object. If you are interested, I can show you how to "manually" decode the attributes before the |
So, I haven't actually tried to compile this, but you should be able to do something like the following in let crate_entry = crate_root
.index
.lookup(metadata.raw_bytes(), CRATE_DEF_INDEX)
.unwrap()
.decode(&metadata);
let crate_attrs = crate_entry
.attributes
.decode((&metadata, self.sess))
.collect(); |
@michaelwoerister that's very close to what I had been trying and results in the same issue with the decoder. I have pushed these changes up so that you can see the error I'm talking about and maybe we can figure out a way around it? So you don't have to wait for the build to see the error, here it is. It occurs when compiling
It appears to be due to https://github.com/rust-lang/rust/blob/master/src/librustc_metadata/decoder.rs#L341 As a total side note, I noticed that |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ah, I see what's going on. Attributes contain spans and for decoding those we need to be able to import FileMaps. This, in turn, needs the CrateMetadata for caching stuff. I think the best way to solve this is to already convert the crate attributes in question to booleans already during serialization. They would be fields of CrateRoot defined in schema.rs and set in encoder.rs. Then the crate attributes wouldn't have to be decoded at all. |
☔ The latest upstream changes (presumably #50686) made this pull request unmergeable. Please resolve the merge conflicts. |
@michaelwoerister good idea! I've implemented that, I think, and all the tests seem to pass. Want to take another look at this and see if the performance is any better? I removed the unnecessary |
Alright, now we are seeing actual performance improvements: @whitfin, if you fix the compile errors, this should be ready to go! |
@michaelwoerister is there something specific you're referring to? It looks like the last CI build ran successfully! If I'm missing something, just drop me a note and I'll pick it up ASAP! |
📌 Commit d95ba30 has been approved by |
⌛ Testing commit d95ba30 with merge 9380fd2d098bdc5c7c32bd9f33703d56ee259aa9... |
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
@bors retry 30 minute no output while linking LLVM binaries again 🤔 |
⌛ Testing commit d95ba30 with merge e0bee604b298fa412ce34401ba11dbf2a578cb3c... |
💔 Test failed - status-appveyor |
@bors retry Failed to clone llvm or something |
Remove attribute_cache from CrateMetadata This PR will fix #50508 by removing the `attribute_cache` from the `CrateMetadata` struct. Seeing as performance was referenced in the original issue, I also cleaned up a `self.entry(node_id);` call which might have occasionally happened redundantly. r? @michaelwoerister
☀️ Test successful - status-appveyor, status-travis |
This PR will fix #50508 by removing the
attribute_cache
from theCrateMetadata
struct. Seeing as performance was referenced in the original issue, I also cleaned up aself.entry(node_id);
call which might have occasionally happened redundantly.r? @michaelwoerister