-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Use dynamic dispatch for queries #108638
Use dynamic dispatch for queries #108638
Conversation
These commits modify the If this was intentional then you can ignore this comment. |
79f8763
to
4b8bcb6
Compare
This could use a perf run. |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 4b8bcb6bb27ac0f3fabaa33bedfd3921487100ea with merge 97d7f37551bbf61e755d3ee780318d260f4dfb64... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (97d7f37551bbf61e755d3ee780318d260f4dfb64): comparison URL. Overall result: ❌ regressions - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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.
|
|
061d6ef
to
544955a
Compare
☔ The latest upstream changes (presumably #108863) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
This PR is very complex. It will take me a few more passes to fully digest it.
Thanks you for the work (and your future patience).
The bootstrap gains are nice, but the 2% regression is a bit much.
Do you have ideas to mitigate it?
compiler/rustc_query_impl/src/lib.rs
Outdated
} | ||
|
||
impl<'tcx, C: QueryCache, Anon: Bool, DepthLimit: Bool, Feedable: Bool> QueryConfig<QueryCtxt<'tcx>> | ||
for DynamicConfig<'tcx, C, Anon, DepthLimit, Feedable> |
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.
IIUC, we now have 2 (Anon) x 2 (DepthLimit) x 2 (Feedable) x 3 (types of cache) x (number of value sizes) instance of the functions in rustc_query_system
.
Is there much gained by having anon/depth_limit/feedable statically, instead of plain booleans?
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.
Anon, DepthLimit and Feedable have few instances, so the cost of specializing for them is quite low at the moment. Fully erased we reduce things to 94 instances so few additional ones isn't impactful.
mode: QueryMode, | ||
) -> Option<query_values::$name<'tcx>> { | ||
) -> Option<Erase<query_values::$name<'tcx>>> { |
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.
We could use a query_erased::$name
alias for the return type.
There's 2 additional optimizations that can be done, re-merging query state and query cache and making |
Finished benchmarking commit (c5ee29edea029fc90cd1b1fcf1c9701733aef5aa): comparison URL. Overall result: ❌ regressions - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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. |
I think the current state is decent enough. I did some more local testing and the incremental regressions seems to be about 0.3% on average (perf showing 0.2% for primary benchmarks on incr-unchanged + incr-patched). The performance to compile time ratio improvement is good. For builds with 1 CGU it's a 15% reduction in the compile time of the compiler with 8 cores. This means that switching to building the compiler with 1 CGU would give us extra performance while building faster than with 16 CGUs with 8 cores (which is the highest CI uses). @rustbot ready |
I agree, the perf effect is only visible on incr-unchanged cases, and ~1% on perf suite. Meanwhile, we get a ~20s gain on bootstrap. |
memoffset = { version = "0.6.0", features = ["unstable_const"] } | ||
field-offset = "0.3.5" |
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.
This creates 3 versions of memoffset
(0.6, 0.7, 0.8). Is there particular reason to use 0.6 version instead of 0.7 or 0.8?
☀️ Test successful - checks-actions |
Finished benchmarking commit (8e8116c): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 659.942s -> 641.664s (-2.77%) |
pub fn dynamic_queries<'tcx>() -> DynamicQueries<'tcx> { | ||
DynamicQueries { | ||
$( | ||
$name: dynamic_query::$name(), | ||
)* | ||
} | ||
})* | ||
} |
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.
And now this is top4 function by size 56kb long.
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.
That doesn't sound right? What's the symbol name and content?
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.
_RNvCscI0NJ2NbQrx_16rustc_query_impl15dynamic_queries() | 55826
, i guess inlined dynamic_query
calls? I'll try place inline(never) over it.
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.
Hm.. I guess they all could end up getting inlined. It should be a single basic block though, so it might not affect compile time much.
…lacrum deps: bump crates Updates few deps: drops a lot of cxx* crates: ```console $ cargo update -p iana-time-zone-haiku Updating crates.io index Updating cc v1.0.77 -> v1.0.79 Removing codespan-reporting v0.11.1 Removing cxx v1.0.94 Removing cxx-build v1.0.94 Removing cxxbridge-flags v1.0.94 Removing cxxbridge-macro v1.0.94 Updating iana-time-zone-haiku v0.1.1 -> v0.1.2 Removing link-cplusplus v1.0.8 Removing scratch v1.0.5 ``` cc: https://github.com/rust-lang/cc-rs/releases/tag/1.0.78, https://github.com/rust-lang/cc-rs/releases/tag/1.0.79 iana-time-zone-haiku: https://github.com/strawlab/iana-time-zone/releases/tag/haiku%2Fv0.1.2 fixed crossbeam-rs/crossbeam#972 (similar fixed in rust repo rust-lang#110089) ```console $ cargo update -p crossbeam-channel Updating crates.io index Updating crossbeam-channel v0.5.6 -> v0.5.8 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-channel/CHANGELOG.md#version-058 dedupes memoffset versions: ```console $ cargo update -p crossbeam-epoch Updating crates.io index Updating crossbeam-epoch v0.9.13 -> v0.9.14 Removing memoffset v0.7.1 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-epoch/CHANGELOG.md#version-0914 Gilnaa/memoffset@v0.6.5...v0.8.0 rust-lang#108638 (comment) dedupes bstr versions ```console $ cargo update -p ignore -p opener Updating crates.io index Removing bstr v0.2.17 Updating globset v0.4.9 -> v0.4.10 Updating ignore v0.4.18 -> v0.4.20 Updating opener v0.5.0 -> v0.5.2 ``` globset BurntSushi/ripgrep@ac8fecb ignore https://github.com/BurntSushi/ripgrep/commits/master/crates/ignore hard to track, but drop dep on crossbeam-utils (BurntSushi/ripgrep@e95254a), don't stat git if require_git is false (BurntSushi/ripgrep@009dda1) and added bunch of formats to ignore list opener Seeker14491/opener@v0.5.0...v0.5.2 nothing interesting
deps: bump crates Updates few deps: drops a lot of cxx* crates: ```console $ cargo update -p iana-time-zone-haiku Updating crates.io index Updating cc v1.0.77 -> v1.0.79 Removing codespan-reporting v0.11.1 Removing cxx v1.0.94 Removing cxx-build v1.0.94 Removing cxxbridge-flags v1.0.94 Removing cxxbridge-macro v1.0.94 Updating iana-time-zone-haiku v0.1.1 -> v0.1.2 Removing link-cplusplus v1.0.8 Removing scratch v1.0.5 ``` cc: https://github.com/rust-lang/cc-rs/releases/tag/1.0.78, https://github.com/rust-lang/cc-rs/releases/tag/1.0.79 iana-time-zone-haiku: https://github.com/strawlab/iana-time-zone/releases/tag/haiku%2Fv0.1.2 fixed crossbeam-rs/crossbeam#972 (similar fixed in rust repo rust-lang/rust#110089) ```console $ cargo update -p crossbeam-channel Updating crates.io index Updating crossbeam-channel v0.5.6 -> v0.5.8 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-channel/CHANGELOG.md#version-058 dedupes memoffset versions: ```console $ cargo update -p crossbeam-epoch Updating crates.io index Updating crossbeam-epoch v0.9.13 -> v0.9.14 Removing memoffset v0.7.1 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-epoch/CHANGELOG.md#version-0914 Gilnaa/memoffset@v0.6.5...v0.8.0 rust-lang/rust#108638 (comment) dedupes bstr versions ```console $ cargo update -p ignore -p opener Updating crates.io index Removing bstr v0.2.17 Updating globset v0.4.9 -> v0.4.10 Updating ignore v0.4.18 -> v0.4.20 Updating opener v0.5.0 -> v0.5.2 ``` globset BurntSushi/ripgrep@ac8fecb ignore https://github.com/BurntSushi/ripgrep/commits/master/crates/ignore hard to track, but drop dep on crossbeam-utils (BurntSushi/ripgrep@e95254a), don't stat git if require_git is false (BurntSushi/ripgrep@009dda1) and added bunch of formats to ignore list opener Seeker14491/opener@v0.5.0...v0.5.2 nothing interesting
deps: bump crates Updates few deps: drops a lot of cxx* crates: ```console $ cargo update -p iana-time-zone-haiku Updating crates.io index Updating cc v1.0.77 -> v1.0.79 Removing codespan-reporting v0.11.1 Removing cxx v1.0.94 Removing cxx-build v1.0.94 Removing cxxbridge-flags v1.0.94 Removing cxxbridge-macro v1.0.94 Updating iana-time-zone-haiku v0.1.1 -> v0.1.2 Removing link-cplusplus v1.0.8 Removing scratch v1.0.5 ``` cc: https://github.com/rust-lang/cc-rs/releases/tag/1.0.78, https://github.com/rust-lang/cc-rs/releases/tag/1.0.79 iana-time-zone-haiku: https://github.com/strawlab/iana-time-zone/releases/tag/haiku%2Fv0.1.2 fixed crossbeam-rs/crossbeam#972 (similar fixed in rust repo rust-lang/rust#110089) ```console $ cargo update -p crossbeam-channel Updating crates.io index Updating crossbeam-channel v0.5.6 -> v0.5.8 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-channel/CHANGELOG.md#version-058 dedupes memoffset versions: ```console $ cargo update -p crossbeam-epoch Updating crates.io index Updating crossbeam-epoch v0.9.13 -> v0.9.14 Removing memoffset v0.7.1 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-epoch/CHANGELOG.md#version-0914 Gilnaa/memoffset@v0.6.5...v0.8.0 rust-lang/rust#108638 (comment) dedupes bstr versions ```console $ cargo update -p ignore -p opener Updating crates.io index Removing bstr v0.2.17 Updating globset v0.4.9 -> v0.4.10 Updating ignore v0.4.18 -> v0.4.20 Updating opener v0.5.0 -> v0.5.2 ``` globset BurntSushi/ripgrep@ac8fecb ignore https://github.com/BurntSushi/ripgrep/commits/master/crates/ignore hard to track, but drop dep on crossbeam-utils (BurntSushi/ripgrep@e95254a), don't stat git if require_git is false (BurntSushi/ripgrep@009dda1) and added bunch of formats to ignore list opener Seeker14491/opener@v0.5.0...v0.5.2 nothing interesting
deps: bump crates Updates few deps: drops a lot of cxx* crates: ```console $ cargo update -p iana-time-zone-haiku Updating crates.io index Updating cc v1.0.77 -> v1.0.79 Removing codespan-reporting v0.11.1 Removing cxx v1.0.94 Removing cxx-build v1.0.94 Removing cxxbridge-flags v1.0.94 Removing cxxbridge-macro v1.0.94 Updating iana-time-zone-haiku v0.1.1 -> v0.1.2 Removing link-cplusplus v1.0.8 Removing scratch v1.0.5 ``` cc: https://github.com/rust-lang/cc-rs/releases/tag/1.0.78, https://github.com/rust-lang/cc-rs/releases/tag/1.0.79 iana-time-zone-haiku: https://github.com/strawlab/iana-time-zone/releases/tag/haiku%2Fv0.1.2 fixed crossbeam-rs/crossbeam#972 (similar fixed in rust repo rust-lang/rust#110089) ```console $ cargo update -p crossbeam-channel Updating crates.io index Updating crossbeam-channel v0.5.6 -> v0.5.8 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-channel/CHANGELOG.md#version-058 dedupes memoffset versions: ```console $ cargo update -p crossbeam-epoch Updating crates.io index Updating crossbeam-epoch v0.9.13 -> v0.9.14 Removing memoffset v0.7.1 ``` https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-epoch/CHANGELOG.md#version-0914 Gilnaa/memoffset@v0.6.5...v0.8.0 rust-lang/rust#108638 (comment) dedupes bstr versions ```console $ cargo update -p ignore -p opener Updating crates.io index Removing bstr v0.2.17 Updating globset v0.4.9 -> v0.4.10 Updating ignore v0.4.18 -> v0.4.20 Updating opener v0.5.0 -> v0.5.2 ``` globset BurntSushi/ripgrep@ac8fecb ignore https://github.com/BurntSushi/ripgrep/commits/master/crates/ignore hard to track, but drop dep on crossbeam-utils (BurntSushi/ripgrep@e95254a), don't stat git if require_git is false (BurntSushi/ripgrep@009dda1) and added bunch of formats to ignore list opener Seeker14491/opener@v0.5.0...v0.5.2 nothing interesting
This replaces most concrete query values
V
withMaybeUninit<[u8; { size_of::<V>() }]>
reducing the code instantiated by queries. The compile time ofrustc_query_impl
is reduced by 27%. It is an alternative to #107937 which uses unstable const generics while this uses aEraseType
trait which maps query values to their erased variant.This is achieved by introducing an
Erased
type which does sanity check withcfg(debug_assertions)
. The query caches gets instantiated with these erased types leaving the code inrustc_query_system
unaware of them.rustc_query_system
is changed to use instances ofQueryConfig
so thatrustc_query_impl
can pass inDynamicConfig
which holds a pointer to a virtual table.It's based on #108167.
r? @cjgillot