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 upInstantiate fewer copies of a closure inside a generic function #46477
Comments
This comment has been minimized.
This comment has been minimized.
|
cc @michaelwoerister @eddyb @arielb1 Seems like this has potential for some fairly large wins across Rust. |
Mark-Simulacrum
added
I-compiletime
P-medium
T-compiler
labels
Dec 3, 2017
This comment has been minimized.
This comment has been minimized.
|
This is a subset of being able to detect parameter dependence from MIR, and sharing instances on the monomorphization collector based on it. EDIT: in fact, I think all you need is to implement |
This comment has been minimized.
This comment has been minimized.
|
Interesting find! |
TimNN
added
the
C-enhancement
label
Dec 5, 2017
This comment has been minimized.
This comment has been minimized.
|
Just to leave a breadcrumb for later, there are other good suggestions for similar kinds of optimizations that can be done in this internals thread. |
dtolnay commentedDec 3, 2017
In serde-rs/json#386 we observed that a disproportionately large amount of serde_json lines of LLVM IR and compile time are due to a tiny closure inside a generic function. In fact this closure contributes more LLVM IR than all but 5 significantly larger functions.
The generic function needs to be instantiated lots of times, but the closure does not capture anything that would be affected by the type parameter.
Simplified example:
This gives the expected 1 copy of
fand 2 copies ofg, but unexpectedly 2 copies ofg::{{closure}}in the IR.@Mark-Simulacrum