-
Notifications
You must be signed in to change notification settings - Fork 49
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
Support for compilers prior to Rust 1.55 causing high compile times #161
Comments
hmmmmmmmmm how much of this impacts rebuild times when the crate is used as a dep? I do want fast builds, but I think that if only the initial build is longer that's probably acceptable. We're only talking a difference of 0.3 seconds here after all. Either way I'm happy to at least have the docs. I'm much less enthused by the idea of a minimum Rust bump in a minor version but if it's just a default feature change and a person can just fiddle with their deps entry to compensate that's probably okay i guess. |
The saving will of course only occur when the crate is compiled/recompiled (which includes the initial build, and the initial |
Ah, so it's not quite like normal generics where the monomorph cost of the code is paid by the downstream crate each time it rebuilds? |
Oh, good point, I hadn't considered that. So it's possible the benefits are larger than I said. |
While casually reading https://hackmd.io/mxdn4U58Su-UQXwzOHpHag (Analysis of rustc-benchmarking-data), I noticed that it mentions Lokathor/tinyvec#161. The tinyvec crate, with the default set of features, can compile on rustc < 1.55 by using large implementations of Default for [T; N]. On Rustc >= 1.55, it can elide this code and just use const generics. Apparently this reduces compilation time for tinyvec by about half - which is not a lot in the context of librsvg, but let's make use of that. Librsvg currently requires Rust >= 1.64.0 anyway, so we can make use of tinyvec's rustc_1_55 feature.
While casually reading https://hackmd.io/mxdn4U58Su-UQXwzOHpHag (Analysis of rustc-benchmarking-data), I noticed that it mentions Lokathor/tinyvec#161. The tinyvec crate, with the default set of features, can compile on rustc < 1.55 by using large implementations of Default for [T; N]. On Rustc >= 1.55, it can elide this code and just use const generics. Apparently this reduces compilation time for tinyvec by about half - which is not a lot in the context of librsvg, but let's make use of that. Librsvg currently requires Rust >= 1.64.0 anyway, so we can make use of tinyvec's rustc_1_55 feature. Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/822>
I have been working on Rust compiler performance, guided by this analysis document that looks at compilation of 800 popular crates. It identifies
tinyvec
as an interesting case, being the only crate out of those 800 to cause thediverge_cleanup
function within the compiler to be very hot.I just looked into this, and it's caused by the very large array literals in the various
default
methods withingenerated_impl.rs
. I don't see an easy way to speed up the compiler's handling of these literals, and the rarity of this case suggests it's not worth much effort to improve.Fortunately, there's an alternative solution already present in
tinyvec
: therustc_1_55
feature uses const generics to avoid the need forgenerated_impl.rs
. I just did some simple benchmarking, andtinyvec-1.6.0
compiles about twice as fast whenrustc_1_55
is enabled. Here are numbers for three kinds of non-incremental builds.There are several possible ways to make the faster compile times more widely available.
rustc_1_55
, which currently isn't mentioned in the README or the rustdocs.Defaults matter, so the first or second option would be preferable.
It's also possible to use a
build.rs
to auto-detect the Rust version being used, but compiling and running the build script takes a non-trivial amount of time and would eat into the savings, so I don't recommend doing that.Anyway, I hope this is useful information! Fast compile times are good for everybody :) I'm happy to answer any questions you might have.
The text was updated successfully, but these errors were encountered: