Cache derive proc macro expansion with incremental query - #145354
Conversation
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Cache derive proc macro expansion with incremental query
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
|
@bors try |
This comment has been minimized.
This comment has been minimized.
Cache derive proc macro expansion with incremental query
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
|
I looked into the benchmark failure on diesel, seems like I hold queries wrong somehow :) Any suggestions on what could be the case? Maybe the derived |
|
Ok I did a bit of debugging, and found a fun fact: |
|
Ok I found it, it's this. @nnethercote Do you think it's possible to make |
|
Technically, removing that I'm not actually sure where else |
|
Could you please specify what do you mean by "macro rules matching logic"? I tried removing I also thought that another alternative would be to wrap |
|
@rustbot ready |
|
r=me after addressing the remaining nits and squashing commits. |
05781ca to
8fa2f69
Compare
|
@bors r=petrochenkov |
…henkov Cache derive proc macro expansion with incremental query This is a revival of rust-lang#129102, originally implemented by @futile. Since it looks like they are not active currently, I'd like to push this work forward. The first commit is squashed and rebased work from the original PR, with author attribution to futile. The rest of the commits are some additional comments that I created mostly for myself to understand what happens here. I also did some cleanups based on Vadim's review comments on the original PR, plus I refactored the TLS access a bit using `scoped_tls`. The biggest issue, as usually, are tests... I tried using `#[rustc_clean(..., loaded_from_disk = "derive_macro_expansion")]`, but the problem is that since this query cannot recover the original key from its hash, and thus its fingerprintstyle is `FingerprintStyle::Opaque`, [this](https://github.com/rust-lang/rust/blob/2fef0a30ae6b2687dfb286cb544d2a542f7e2335/compiler/rustc_incremental/src/persist/dirty_clean.rs#L388) crashes when I try to use `loaded_from_disk`. Any suggestions from someone who actually understands the query system would be welcome 😅 TODO: document the new unstable flag On a no-op change re-check of `octocrab 0.49` (which has a ton of `serde` derive proc macro invocations), this saves ~0.6s out of ~6s (so a ~10% win) on my PC. r? @petrochenkov
Rollup of 6 pull requests Successful merges: - #145354 (Cache derive proc macro expansion with incremental query) - #151123 (Support primitives in type info reflection) - #151178 (simplify words initialization using Rc::new_zeroed) - #151187 (Use `default_field_values` more in `Resolver`) - #151197 (remove lcnr from compiler review rotation) - #151203 (Revert `QueryStackFrame` split) r? @ghost
Rollup merge of #145354 - cache-proc-derive-macros, r=petrochenkov Cache derive proc macro expansion with incremental query This is a revival of #129102, originally implemented by @futile. Since it looks like they are not active currently, I'd like to push this work forward. The first commit is squashed and rebased work from the original PR, with author attribution to futile. The rest of the commits are some additional comments that I created mostly for myself to understand what happens here. I also did some cleanups based on Vadim's review comments on the original PR, plus I refactored the TLS access a bit using `scoped_tls`. The biggest issue, as usually, are tests... I tried using `#[rustc_clean(..., loaded_from_disk = "derive_macro_expansion")]`, but the problem is that since this query cannot recover the original key from its hash, and thus its fingerprintstyle is `FingerprintStyle::Opaque`, [this](https://github.com/rust-lang/rust/blob/2fef0a30ae6b2687dfb286cb544d2a542f7e2335/compiler/rustc_incremental/src/persist/dirty_clean.rs#L388) crashes when I try to use `loaded_from_disk`. Any suggestions from someone who actually understands the query system would be welcome 😅 TODO: document the new unstable flag On a no-op change re-check of `octocrab 0.49` (which has a ton of `serde` derive proc macro invocations), this saves ~0.6s out of ~6s (so a ~10% win) on my PC. r? @petrochenkov
|
Congratz @Kobzol, and thanks for seeing this through! The final code looks super nice. And thanks to @petrochenkov for all the reviews :) Looking forward to updating to the next nightly 😀 |
… r=jackh726 Document `-Zcache-proc-macros` Forgot about this in rust-lang#145354. Created a tracking issue in rust-lang#151364.
…4595) # Objective Add flag to improve incremental build times. ## Solution Add the flag `-Zcache-proc-macros` to config_fast_build_times.config so that a user can easily enable it if they want to. ## Testing I did a few tests back and forth with and without this on Linux. I saw consistent incremental build time gains, maybe around 5%. I've also been running with this on aarch64 Mac so it compiles there as well. I haven't tested this on Windows. I unfortunately did not save the run results I gathered. --- Another thing to note is that this might _slightly_ increase clean compilation times but only by a small fraction (maybe a couple of percent, not sure). I'm guessing this might be a hot path in the compiler so branching on this condition every time could possibly make it slightly slower? Or it might have just been noise. The claim that it improves incremental by 5-10% is based on my own experiments and the original rust [PR](rust-lang/rust#145354) that states > On a no-op change re-check of octocrab 0.49 (which has a ton of serde derive proc macro invocations), this saves ~0.6s out of ~6s (so a ~10% win) on my PC. Maybe we shouldn't give a number at all? It might even be the case that a user doesn't notice this a lot of the time. My suspicion is that this would make more of a difference if a crate has many and large derive macros, relative to the rest of the code size. Also I asked about this in the Discord server, but this will probably return stale results if a proc macro if there are side effects. Does Bevy have any side effects in proc macros?
This is a revival of #129102, originally implemented by @futile. Since it looks like they are not active currently, I'd like to push this work forward.
The first commit is squashed and rebased work from the original PR, with author attribution to futile. The rest of the commits are some additional comments that I created mostly for myself to understand what happens here. I also did some cleanups based on Vadim's review comments on the original PR, plus I refactored the TLS access a bit using
scoped_tls.The biggest issue, as usually, are tests... I tried using
#[rustc_clean(..., loaded_from_disk = "derive_macro_expansion")], but the problem is that since this query cannot recover the original key from its hash, and thus its fingerprintstyle isFingerprintStyle::Opaque, this crashes when I try to useloaded_from_disk. Any suggestions from someone who actually understands the query system would be welcome 😅You can try it yourself on nightly with
RUSTFLAGS="-Zcache-proc-macros" cargo +nightly build.On a no-op change re-check of
octocrab 0.49(which has a ton ofserdederive proc macro invocations), this saves ~0.6s out of ~6s (so a ~10% win) on my PC.Tracking issue: #151364
r? @petrochenkov