-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Remove bitflags dependency #1436
Conversation
The only real use of bitflags was to save a tiny bit of memory. It isn't exposed externally and we can just use a flag enumeration combined with a HashSet to replace it. Because of this, let's not subject this dependency to all projects which depend on clap.
This isn't really something we can merge against |
|
Ah, apologies, your description of the change made it sound this was something re-exported to depending crates. Generally breaking changes are being made on So...I don't really have an opinion on merging this. I will leave it open for a bit longer to let other maintainers voice concerns if they have them, otherwise merge it in a few days. |
@spacekookie Should I make separate pull requests against |
I'm not involved in clap development, but I definitely appreciate reducing my dependency list when something isn't carrying its weight. :-) I've been trying to do the same for my crates. |
@npmccallum |
This is a commit I'd like to revert. In favor of removing To be clear, I'm all for reducing deps, and
Depending on the exact use case, this commit can roughly double or triple clap parse time. I'm specifically leery of cases like Here's benchmarks pre-commit:
And post commit:
As for combining settings, Also, when I say combining flags, I'm speaking about internally where clap uses a single user setting, to actually indicate to itself multiple "core" settings are used. I'll wait on the revert to get some other opinions before doing so. |
I should also mention I'm not sure what the balance is between deps and home grown functionality. Some people prefer as few deps as possible, but then others prefer clap to be as lean as possible. So I tend to prefer opt-out deps if possible. In this specific case, I think we're using a small enough portion of |
@kbknapp Thanks for the investigation and attention to performance. :-) Balancing dependencies is tricky. So basically what I usually do for this is to look at two things: 1) holistic performance using For (1), here's an example, on a checkout of the Linux kernel:
(To explain the flags: There's a ton of variance here (which is interesting), but the short story is that this PR definitely seems to be noticeable here. Compare this with grep's performance, which is killing it:
Looking at the output of The other way I benchmark this is with just a single invocation. I use zsh, which means I can use globs to fill up ripgrep's positional arguments easily:
These commands unfortunately have quite a bit of variance (as expected given the hyperfine output above). These are harder to benchmark with hyperfine since they rely on glob expansion. But we can establish a baseline with grep:
This suggests glob expansion might actually be taking a fair bit of time. OK, so let's cache glob expansion in a file:
And now we can use hyperfine and see the difference a bit more clearly:
Finally, if I take perf to My feeling is that this isn't that big of a performance regression. Clap is still fast. But it's definitely measurable and maybe dropping the dependency isn't worth it. But if it's easy to do without bitflags without sacrificing performance, then maybe that's a good path to take. |
Wow, your thoroughness always amazes me! Although I tend to try and stay away from slippery slope mentalities, performance is one where I do worry about the sum of regressions since they can't be considered purely in a vacuum. Allowable performance regressions, while vague because they have to be weighed against any tangible gain, are close to a zero sum game in my optic. Luckily, I think all we really need out of a home grown solution is pretty minimal and easy to implement. So we may well be able to get the best of both worlds. |
All, just to be clear, I'm not offended if you need to revert my previous patch for performance reasons. I'm glad there is still a desire to remove a bitflags dependency. |
The only real use of bitflags was to save a tiny bit of memory. It isn't
exposed externally and we can just use a flag enumeration combined with
a HashSet to replace it. Because of this, let's not subject this
dependency to all projects which depend on clap.