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

Reduce compilation time #2037

Open
1 of 4 tasks
CreepySkeleton opened this issue Jul 28, 2020 · 5 comments
Open
1 of 4 tasks

Reduce compilation time #2037

CreepySkeleton opened this issue Jul 28, 2020 · 5 comments
Labels
A-meta Area: administrative question or tracking issue C-enhancement Category: Raise on the bar on expectations S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation'

Comments

@CreepySkeleton
Copy link
Contributor

CreepySkeleton commented Jul 28, 2020

All features
No features

The clap crate (not counting dependencies) takes about 11 seconds to compile. All dependencies put together take roughly the same amount of time.

I have a few thoughts on how to improve the situation. Generally, compile time wins these days are accomplished through "compile less code", hence:

  • Feature-gate #[derive(Clone, Copy, Eq...]. The features should probably be fine-grained, like impl-traits-eq enables Eq + PartialEq. Plus the "enable everything" impl-traits feature that implies all the traits.
    • Avoid using derives and use some sort of STRUCT! macro as shown here. It turns out that even built-in derives have impact on compilation time when you have lots of them, and every struct here has #[derive(Debug)].
  • Optimize proc-macro-error (drop syn-mid dep). I had already done that but decided to play around a bit more and then forgot about it. Oops.
  • Make clap modular so developers could choose exactly the set of features they need and avoid compile the others. I'll crate a separate issue a bit later.

The list is probably not exhaustive...

@CreepySkeleton CreepySkeleton added T: RFC / question A-meta Area: administrative question or tracking issue labels Jul 28, 2020
@mainrs
Copy link

mainrs commented Jul 30, 2020

Hey!
If you want I can tackle down the trait implementation features :) How fine-grained do you want it to be though?

@CreepySkeleton
Copy link
Contributor Author

Sure, you can try, but keep in mind that the real goal is to reduce compilation time. If the measurements will show no real difference (at least half second, everything below the threshold is noise), I will say "well we tried" and move on to other ideas.

@mainrs
Copy link

mainrs commented Jul 31, 2020

Sure thing! Could you tell me how to managed to time the compilation? And create the visuals for it as well :)

@CreepySkeleton
Copy link
Contributor Author

The invocation was

cargo clean # make sure the we build from scratch
cargo +nightly build -Z timings -p clap:3.0.0-beta.1 --features "yaml unstable"

This will create cargo-timing-<HASH>.html file that you can open in your web browser and see the adorable stats you were so excited about :) Then I uploaded the raw html on gist.github.com and linked it through gistpreview.github.io so you see the rendered version instead of raw HTML guts.

@epage epage added C-enhancement Category: Raise on the bar on expectations S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation' and removed C: other labels Dec 8, 2021
epage added a commit to epage/clap that referenced this issue Aug 17, 2022
With being able to accept owned types now, `clap_derive` no longer needs
`once_cell` to make dynamic data static.

This helps towards clap-rs#1365, clap-rs#2037
epage added a commit to epage/clap that referenced this issue Aug 19, 2022
With being able to accept owned types now, `clap_derive` no longer needs
`once_cell` to make dynamic data static.

This helps towards clap-rs#1365, clap-rs#2037
Calder-Ty pushed a commit to Calder-Ty/clap that referenced this issue Aug 24, 2022
With being able to accept owned types now, `clap_derive` no longer needs
`once_cell` to make dynamic data static.

This helps towards clap-rs#1365, clap-rs#2037
epage added a commit to epage/clap that referenced this issue Aug 25, 2022
The immediate benefit is binary size but this also makes us more
flexible on the implementation, like allowing wrapping of `StyledStr`.

This removed 12 KiB from `.text`

This helps towards clap-rs#1365 and probably clap-rs#2037
@mgeisler
Copy link
Contributor

The clap crate (not counting dependencies) takes about 11 seconds to compile

Hi @CreepySkeleton, I suppose this is a "cold" compilation of a small Hello World-style program which depends on Clap? As a developer, I would be interested in the incremental compilation time when I change my application by, e.g., adding a new command line flag.

Could you perhaps measure that as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: administrative question or tracking issue C-enhancement Category: Raise on the bar on expectations S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation'
Projects
None yet
Development

No branches or pull requests

4 participants