Open
Description
If you look at the trans-stats for some of our modules, some "big functions" really stand out:
rustc:
16838 insns, 67 ms, middle::trans::foreign::trans_intrinsic
15988 insns, 145 ms, middle::typeck::check::check_expr_with_unifier
11759 insns, 87 ms, middle::privacy::check_crate
libextra:
5244 insns, 31 ms, terminfo::parm::expand
5073 insns, 21 ms, time::do_strptime::parse_type
4068 insns, 23 ms, time::do_strftime::parse_type
3610 insns, 73 ms, terminfo::parser::compiled::parse
2169 insns, 89 ms, net_tcp::listen_common
1952 insns, 28 ms, getopts::getopts
1937 insns, 193 ms, net_tcp::connect
If you look at the code generating them, they don't immediately look like they should be taking 10x as long as other functions; but they do all seem to use match
somewhat heavily. This suggests to me that we're still compiling matches in some way that causes a combinatorial explosion of basic blocks, or something.
Investigate!
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Implement scopes independent of LLVM basic blocks
auto merge of #7636 : dotdash/rust/scope_cleanup, r=graydon
emberian commentedon Aug 13, 2013
/cc @toddaaro
emberian commentedon Aug 13, 2013
/cc @msullivan
I don't think it was actually toddaaro I was talking to about this...
toddaaro commentedon Aug 21, 2013
I have whined a lot about match implementations that suffer from combinatorial explosion, so maybe that is why you thought of me.
This Scala issue is probably unrelated, but maybe reading about the experience will prove useful to a Rust developer someday.
https://issues.scala-lang.org/browse/SI-1133
steveklabnik commentedon Jan 20, 2015
Triage: did anyone determine if
match
was still the issue here? I'd imagine codegen has gotten better since 2013...emberian commentedon Jan 20, 2015
@steveklabnik I don't know of any changes to
match
codegen that would have alleviated this, re-running the measurements...emberian commentedon Jan 20, 2015
Yes,
match
is still generating more code than anything else, by a significant margin.steveklabnik commentedon Jan 20, 2015
@cmr if you have a moment, can you explain how you checked this out? Future triage-rs will be thankful 😄
emberian commentedon Jan 20, 2015
make RUSTFLAGS="-Z count-llvm-insns" | tee output
, followed bysort -n < output > output2
, then look at the bottom ofoutput2
(ctrl-f for "trans_match")huonw commentedon Jan 5, 2016
trans-ing a
match
appears to be quadratic in the number of arms (at least for integers and strings):(The python invocation prints code like
fn main() { match 0 { 0 => {} 1 => {} 2 => {} 3 => {} 4 => {} _ => {} } }
with$N + 1
arms.)brson commentedon Jun 10, 2016
Results of @huonw's script above with
rustc 1.11.0-nightly (34505e222 2016-06-08)
:With
-Z orbit
:MIR trans looks to be a lot better at this case.
arielb1 commentedon Jun 10, 2016
@brson
MIR trans's algorithm is indeed very careful to generate a linear number of basic blocks.
29 remaining items