Reduce the amount of interning and layout_of calls in const eval.#74202
Reduce the amount of interning and layout_of calls in const eval.#74202bors merged 5 commits intorust-lang:masterfrom
layout_of calls in const eval.#74202Conversation
|
@bors try @rust-timer queue |
|
Awaiting bors try build completion |
|
⌛ Trying commit 60d032b3f389e3f34d175d0e71658b5ec5e3c85f with merge 5585d82a144a6885bbd224d4aa643c0c95d39fb6... |
|
cc @rust-lang/wg-const-eval |
|
☀️ Try build successful - checks-actions, checks-azure |
|
Queued 5585d82a144a6885bbd224d4aa643c0c95d39fb6 with parent 5db778a, future comparison URL. |
|
Finished benchmarking try commit (5585d82a144a6885bbd224d4aa643c0c95d39fb6): comparison url. |
|
booya 5% perf improvement r? @RalfJung |
|
@bors rollup=never |
src/librustc_middle/ty/sty.rs
Outdated
There was a problem hiding this comment.
This looks pretty different from the old code, is all I can say here.^^ No idea if it changes behavior.
There was a problem hiding this comment.
this is not the same function. The same function invokes this function adn handles all the cases just like they are handled here.
|
I have not seen most of this code ever before, so I do not think I can meaningfully review this. I don't even understand how this reduces interning or Wow, we have |
Interning is reduced by evaluating |
Which entry points, concretely, do you mean here? I tried to follow the code in the diff a bit but it is rather hard. There's a dozen functions on 2-3 different types that are all called the same, and when looking at a |
src/librustc_middle/ty/sty.rs
Outdated
There was a problem hiding this comment.
This also reduces layout_of invocations, because instead of invoking that on tcx.types.usize, we just use the size in try_to_machine_usize
src/librustc_middle/ty/sty.rs
Outdated
There was a problem hiding this comment.
This is used in a mir optimization on every single Assert terminator:
src/librustc_middle/ty/sty.rs
Outdated
There was a problem hiding this comment.
This is used all over the place for array lengths
src/librustc_middle/ty/sty.rs
Outdated
There was a problem hiding this comment.
Oh so on Const we have try_eval_bits and eval but they do not call each other, and there is neither eval_bits nor try_eval. But try_eval exists on ConstKind. But it is not used to implement Const::try_eval_bits, at least not directly... I feel I need to draw a call graph by hand to understand what happens.
There was a problem hiding this comment.
Longer-term I feel like this is really the thing that ought to be called Const, and the existing Const should become ConstAndTy or so... but that is for a separate PR.
|
☔ The latest upstream changes (presumably #74113) made this pull request unmergeable. Please resolve the merge conflicts. |
|
r=me after rebasing. |
|
@bors r=RalfJung |
|
📌 Commit 1bf0993 has been approved by |
|
☀️ Test successful - checks-actions, checks-azure |
|
The perf results from landing don't quite match the earlier results. It's still a win for @oli-obk: did anything change between the earlier run and landing that might explain these worse results? |
|
The only thing could be some changes around inlining due to the restructuring of the modules, but I don't think this should have an effect within a single crate. If I click the red percentages to look at the details, these regressions aren't actually reflected in the detailed view (or I don't know how to read the detailed view). |
|
|
|
While there's indeed a 1.6% regression in |
|
Ah, no I see now. Incremental loading and execution are separated. And apparently loading |
|
|
r? @ghost
If we just want to get at some bits of a constant, we don't need to intern it before extracting those bits.
Also, if we want to read a
usizeorbool, we can fetch the size without invoking a query.