-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Lifetimes of App, Arg, ArgGroup: removing or relaxing #1041
Comments
This is a focus of 3.x so stay tuned. I've been able to get some work done in spurts during lulls in my day job (which have been few and far between this year). Watch the 3x-master branch for details 😉 |
Personally, I'd like to move away from storing Historyclap has two lifetimes for both clap used to only accept Why not use String?clap originally could have used an owned Moving ForwardI want to get away from using We could move to I'm open to ideas. |
`osascript` is the built-in automation program in macOS. The method of triggering the macOS color picker from `osascript` is documented here: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/PromptforaColor.html#//apple_ref/doc/uid/TP40016239-CH86-SW1 There is a weirdness of `osascript` in that `console.log` only writes to `stderr` regardless of the documented "write to stdout" flag. A workaround was found here and linked in the relevant comment: https://apple.stackexchange.com/a/278395 The picker is only attempted when `#[cfg(target_os = "macos")]`. However it's still listed in the "Supported tools" help text because `clap` make it somewhat hard to customize that help text (e.g. generating from the list of tools) because it does not take ownership of strings. Related: clap-rs/clap#1041
`osascript` is the built-in automation program in macOS. The method of triggering the macOS color picker from `osascript` is documented here: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/PromptforaColor.html#//apple_ref/doc/uid/TP40016239-CH86-SW1 There is a weirdness of `osascript` in that `console.log` only writes to `stderr` regardless of the documented "write to stdout" flag. A workaround was found here and linked in the relevant comment: https://apple.stackexchange.com/a/278395 The picker is only attempted when `#[cfg(target_os = "macos")]`. However it's still listed in the "Supported tools" help text because `clap` make it somewhat hard to customize that help text (e.g. generating from the list of tools) because it does not take ownership of strings. Related: clap-rs/clap#1041
I wonder if
I implemented this for |
@epage Thanks for pointing it out. Do you know if there are any performance changes? |
I just ran some of the benchmarks to double check. For a rough comparison, it looks like In terms of memory usage:
|
My bad. Let me rephrase, I am concerned about the performance issues related to running time because of the indirections introduced by kstring or similar such library. Also pure I haven't actually worked with something like this before, so my entire theory can be wrong. |
My first comment was meant to give a rough idea of what runtime performance looks like compared to other options according to |
You don't have to implement it for clap and run the benchmarks. What I am looking for is a small bench implemented purely on a struct containing a string with large number of iterations doing something which involves accessing the string inside the struct and cloning the struct.
Once we have these, if we make sure that the performance is not too bad, we can go ahead with implementation. If the performance is concerning, we can still implement it but should. provide cargo features to let user pick and choose. I haven't looked into kstring, but hopefully it allows something like this. |
cobalt-org/kstring#6 has the code used for the benchmarks as well as the numbers with some basic analysis. The summary is:
For EDIT: I've not updated my charts above but I have dropped the overhead from 10ns to 5ns by not inlining |
When we do this, we should keep the workarounds in #1104 in mind and have an |
This is a part of clap-rs#2870 and is prep for clap-rs#1041 Oddly enough, this dropped the binary size by 200 Bytes Compared to `HEAD~` on `06_rustup`: - build: 6.21us -> 6.23us - parse: 7.55us -> 8.17us - parse_sc: 7.95us -> 7.65us
This is a step towards clap-rs#1041 - `ArgGroup` no longer takes a lifetime - One less field type needs a lifetime For now, we are using a more brute force type (`String`) so we can establish performance base lines. I was torn on whether to use `&str` everywhere or make an `IdRef`. The latter would add a lot of noise that I'm concerned about, so i left it simple for now. `IdRef` would help to communicate the types involved though. Speaking of communicating types, I'm also torn on whether we should use `Id` for all strings or if we should have `Id`, `Name`, etc types to avoid people mixing and matching. This added 18.7 KB. Compared to `HEAD~` on `06_rustup`: - build: 6.23us -> 7.41us - parse: 8.17us -> 9.36us - parse_sc: 7.65us -> 9.29us
The main breakinge change cases: - `&[char]`: now requires removing `&` - All other non-ID `&[_]`: hopefully clap-rs#1041 will make these non-breaking Fixes clap-rs#2870
This helps with - API cleanup by not having ambigious `None`, see clap-rs#950 - Removes ambiguity with `None` when using owned/borrowed types for clap-rs#1041
This is a part of clap-rs#1041 Because `Option<Into<T>>` is ambiguous for `None`, we had to create `Resettable` to workaround it.
Another step towards clap-rs#1041 This isn't the long term type for `PossibleValue::help`, I just wanted to get the lifetime out of the way first before figuring out how help will work.
This is a part of clap-rs#1041 Because `Option<Into<T>>` is ambiguous for `None`, we had to create `Resettable` to workaround it.
Another step towards clap-rs#1041 This isn't the long term type for `PossibleValue::help`, I just wanted to get the lifetime out of the way first before figuring out how help will work.
Another step towards clap-rs#1041 This isn't the long term type for `PossibleValue::help`, I just wanted to get the lifetime out of the way first before figuring out how help will work.
Another step towards clap-rs#1041 This isn't the long term type for `PossibleValue::help`, I just wanted to get the lifetime out of the way first before figuring out how help will work.
Impact: - Binary size: 556.6 KiB to 578.4 KiB - build time: 6.4950 us (7% slower) - parse time: 7.7256 us - parse sc time: 8.1580 us (5% faster) Fixes clap-rs#1041 Fixes clap-rs#2150
Impact: - Binary size: 556.6 KiB to 578.4 KiB - build time: 6.4950 us (7% slower) - parse time: 7.7256 us - parse sc time: 8.1580 us (5% faster) Fixes clap-rs#1041 Fixes clap-rs#2150
This helps with - API cleanup by not having ambigious `None`, see clap-rs#950 - Removes ambiguity with `None` when using owned/borrowed types for clap-rs#1041
This is a part of clap-rs#1041 Because `Option<Into<T>>` is ambiguous for `None`, we had to create `Resettable` to workaround it.
Another step towards clap-rs#1041 This isn't the long term type for `PossibleValue::help`, I just wanted to get the lifetime out of the way first before figuring out how help will work.
Affected Version of clap
All 2.x. Breaking API change
Expected Behavior Summary
I want to decouple groups of options to several structs. I want to have a pair functions: one that adds arguments to an App with generated names, one that generates a structure with the added arguments.
Actual Behavior Summary
Uncompilable: the types don't allow to create String in a function and return a borrow.
Sample code
Proposed solution
Since clap is dependent on its speed it's probably not an option to force 'String' instead of '&str'. However I think Cow should give enough options.
Alternative for me
Create a struct
AParse
to contain the owned strings, split the functionarguments
in two parts. A can generate anAParse
struct before creating the App object.The text was updated successfully, but these errors were encountered: