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

feat: Allow turning off error-context, auto-help, and auto-usage #4236

merged 11 commits into from Sep 19, 2022


Copy link

@epage epage commented Sep 19, 2022

I originally hesitated over doing this because I do not want these feature flags to be a crutch. However, as I was analyzing where our size goes, I felt it'd be useful to see where the size goes broken up by major feature.

Features and sizes

  • default: 544.3 KiB (up from 542.9 KiB)
    • Probably because of extra book keeping, like usage generation returning an Option
  • -usage: 520.0 KiB
  • -help: 495.3 KiB
  • -error-context: 544.3 KiB
  • -suggestions: 523.0 KiB (existing)
  • -color: 504.0 KiB (existing, down from 533.8 KiB)

Removing everything gets you 422.6 KiB.

I collected the numbers based on subtracting from default because colors cost might scale with the number of features using it so I wanted to see the largest difference.

I optimized color because I'm hoping we can get similar looking code in the future and wanted to see what the potential gains would look like. StyledStr itself appears to be expensive and I'm hoping we can switch from delayed rendered to eager rendering to ANSI with conversion to wincon when needed.

Fixes #1384

This is a cheap pass at creating this to allow cutting out the cost of
rich error information / programmatic error information.

This cuts about 20 KiB off of the binary.

There is more we could cut out, like collecting of used arguments for
the usage, but I want to keep the conditionals simple.
This takes off another 14 KiB when color us not used.  My hope is that
we'll be able to switch away from `termcolor` to a term styling crate
that will make this work in the color case as well.
This removes auto-generated help, saving about 50 KiB.
Quality of error-context goes down with this.
@epage epage merged commit c26e7fd into clap-rs:master Sep 19, 2022
21 checks passed
@epage epage deleted the usage branch September 19, 2022 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

Please support a feature to omit all help and messages
1 participant