Skip to content
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

Improve compile times #52

Closed
iliekturtles opened this issue Jan 20, 2018 · 6 comments
Closed

Improve compile times #52

iliekturtles opened this issue Jan 20, 2018 · 6 comments

Comments

@iliekturtles
Copy link
Owner

Compiling uom with all features enabled takes a significant amount of time. -Ztime-passes shows that the issue is in privacy checking:

$ RUSTFLAGS="-Ztime-passes" cargo +nightly test --no-run
...
time: 172.929; rss: 507MB	privacy checking
...

Timing for this pass increases linearly with the number of underlying storage types enabled. Enabling features for underlying storage types adds impl blocks and type aliases for existing types. No new types are added. Additionally, all structs and traits are pub in uom.

The graph below shows compile times, as reported by cargo for test --no-run in blue and build in red:
image

Test Build Features
15.74 5.5 f64
20.4 5.43 f32,f64
38.84 6.24 bigrational,f32,f64
37.75 7.4 rational64,bigrational,f32,f64
48.28 8.26 rational32,rational64,bigrational,f32,f64
55.52 9.26 rational,rational32,rational64,bigrational,f32,f64
67.57 10.89 biguint,rational,rational32,rational64,bigrational,f32,f64
96.81 12.5 bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
94.53 15.21 i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
106.92 16.4 i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
116.34 18.17 i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
131.29 20.2 i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
144.3 22.19 isize,i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
137.48 24.67 u64,isize,i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
158.4 26.93 u32,u64,isize,i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
194.9 29.69 u16,u32,u64,isize,i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
211.47 33.53 u8,u16,u32,u64,isize,i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
198.5 36.63 usize,u8,u16,u32,u64,isize,i8,i16,i32,i64,bigint,biguint,rational,rational32,rational64,bigrational,f32,f64
iliekturtles added a commit that referenced this issue Apr 24, 2018
Compiler performance issues described in #52 are causing the `uom` build
to take a significant amount of time when all underlying storage types
are enabled. As additional quantities are added this performance gets
worse. This commit only tests a few types in order to keep the build
time within Appveyor and TravisCI limits.
@iliekturtles
Copy link
Owner Author

Initial investigation shows that the storage_types! calls in quantity! that add $crate::Conversion<V> and super::Conversion<V> impl blocks are the culprit. Commenting out these impls makes compilation significantly faster.

iliekturtles added a commit that referenced this issue Apr 30, 2018
Include `cargo test --no-run` for the same feature set as `cargo build`
to catch these errors in the future. #52 needs to be resolved to reduce
compile times before all features can be enabled.
iliekturtles added a commit that referenced this issue Apr 30, 2018
Include `cargo test --no-run` for the same feature set as `cargo build`
to catch these errors in the future. #52 needs to be resolved to reduce
compile times before all features can be enabled for `cargo test`.
iliekturtles added a commit that referenced this issue May 2, 2018
The `si` feature is included when tests are run with a smaller set of
storage types. Part of #52.
@juleskers
Copy link

juleskers commented May 3, 2018

(Hi from the 'what are you up to this week' thread)

Maybe this blogpost about claps weight-reduction can help?
https://clap.rs/2018/01/09/new-years-weight-loss/ (sorry, the title sounds a bit spammy)
This uses the excellent cargo bloat), which helped kbknapp see where his macros where unexpectedly recursing, and some refactoring brought down the total code size (and thus, compile time).

Admittedly, the blog is mostly about binary size, but on the assumption that "more generated code == more compile time", it might pay to have a look.

@iliekturtles
Copy link
Owner Author

I'm pretty sure macro recursion isn't the issue, but reviewing the output of cargo bloat is a good idea!

@juleskers
Copy link

Yeah, from the issue description, and the mostly linear time relation with the number of enabled features (excellent benchmark, b.t.w.), it's probably just the linear amount of complex implementations.

But who knows, maybe bloat can help you identify some potential optimisations in those traits. :-)

iliekturtles added a commit that referenced this issue May 4, 2018
Private aliases to public types cause a significant performance
bottleneck in the privacy checking phase of compilation. Enable more
features in CI build scripts to ensure better test coverage. Part of #52.
iliekturtles added a commit that referenced this issue May 4, 2018
Private aliases to public types cause a significant performance
bottleneck in the privacy checking phase of compilation. Enable more
features in CI build scripts to ensure better test coverage. Part of #52.
@iliekturtles
Copy link
Owner Author

I pushed 224db41 recently that makes a big dent in the problem! The issue is related to private type aliases of public types. Making the type alias public cuts a clean build with --all-features from 1137.24 s down to 28.68 s on one of my machines! A build with default features goes from 25.94 s to 5.73 s.

I did eventually get cargo bloat running after some technical delays and and the results seem to show that uom, at least for the si example, is fully inlined: https://gist.github.com/iliekturtles/474e950b544c268d3c600567f0f60bd8.

I'm leaving the issue open for the moment as I want to submit a report upstream.

@iliekturtles
Copy link
Owner Author

Closing this issue. Upstream issue triaged and current uom compile times are reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants