Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[nll] optimize tuple-stress benchmark by skipping visit of types that do not have regions #52027
Comments
nikomatsakis
added
I-nominated
E-mentor
WG-compiler-nll
NLL-performant
labels
Jul 3, 2018
nikomatsakis
changed the title
[nll] optimize tuple-stress benchmark
[nll] optimize tuple-stress benchmark by skipping visit of types that do not have regions
Jul 3, 2018
nikomatsakis
added this to the Rust 2018 Preview 2 milestone
Jul 3, 2018
lqd
self-assigned this
Jul 3, 2018
This comment has been minimized.
This comment has been minimized.
|
FWIW, I think the first code snippet in the above description should be this: rust/src/librustc_mir/borrow_check/nll/type_check/liveness.rs Lines 85 to 92 in 860d169 |
nikomatsakis
referenced this issue
Jul 3, 2018
Closed
[nll] only compute liveness for variables whose types include regions #52034
lqd
referenced this issue
Jul 3, 2018
Merged
NLL Liveness: Skip regionless types when visiting free regions #52037
bors
added a commit
that referenced
this issue
Jul 4, 2018
bors
added a commit
that referenced
this issue
Jul 7, 2018
bors
closed this
in
#52037
Jul 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nikomatsakis commentedJul 3, 2018
The tuple-stress benchmark appears to be ridiculously slow with NLL. Profiling suggests that the majority of costs come from the liveness constraint generation code:
rust/src/librustc_mir/borrow_check/nll/type_check/liveness.rs
Lines 36 to 42 in 860d169
Specifically, the vast majority of samples (50%) occur in the
push_type_live_constraintfunction:rust/src/librustc_mir/borrow_check/nll/type_check/liveness.rs
Lines 158 to 163 in 860d169
This function primarily consists of a walk over all the free regions within a type:
rust/src/librustc_mir/borrow_check/nll/type_check/liveness.rs
Lines 170 to 172 in 860d169
However, the types in question don't really involve regions (they are things like
(u32, f64, u32)etc). It turns out that we have a "flags" mechanism that tracks the content of types, designed for just such a purpose. This should allow us to quickly skip. The flags are defined here, using thebitflags!macro:rust/src/librustc/ty/mod.rs
Lines 418 to 419 in 860d169
The flag we are interested in
HAS_FREE_REGIONS:rust/src/librustc/ty/mod.rs
Lines 432 to 434 in 860d169
We should be able to optimize the
for_each_free_regionto consult this flag and quickly skip past types that do not contain any regions.for_each_free_regionis defined here:rust/src/librustc/ty/fold.rs
Lines 256 to 260 in 860d169
It uses a "type visitor" to do its work:
rust/src/librustc/ty/fold.rs
Lines 289 to 290 in 860d169
we want to add callback for the case of visiting types which will check this flag. Something like the following ought to do it: