-
-
Notifications
You must be signed in to change notification settings - Fork 38
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: use string replaces instead of splits #64
Conversation
Using a split/join results in a lot of garbage collection for the unused arrays, along with being fairly slow. This just moves to using a RegExp replace instead. Bench result: > 3,410 ops/sec Bench result on main: > 1,150 ops/sec
Just a quick heads up: The strategy LGTM, but I haven't had time to think about the risk of this PR. Could this introduce bugs that the current test suite isn't covering? |
it shouldn't really, we're basically using split/join as a way to emulate i haven't used i'm not sure how we can definitely prove this though 🤔 even with no match, |
@juliangruber just chasing up on this, any chance we can move it forward? also would be good to know if there's a way we can provide this perf change to 2.x too. though no worries if its too much of a pain to backport |
Could you share with me why the speed up is important to you? |
As part of an ecosystem cleanup effort, we're moving a bunch of projects from braces to brace-expansion. In some of those projects, enough expansions happen that this slowdown becomes easy to observe. So the maintainers generally didn't want to use brace-expansion because of that. For example, i'm in the middle of helping rewrite chokidar and wanted to use brace-expansion, but it slowed the benchmark by a large amount (although that is irrelevant now admittedly since we don't want to support globs anymore). |
Thank you for sharing! That is very valid indeed. I'm thinking about releasing this as a new major version, to just bring the risk down as much as possible. The the existing users shouldn't mind if they stay on a slower version if they don't upgrade. Would that work for you? |
that's fair enough, i think it sounds like a sensible strategy 👍 i'll be pushing for migrating a few repos to this too so will make sure i get them on the latest major at the same time |
Using a split/join results in a lot of garbage collection for the unused arrays, along with being fairly slow. This just moves to using a RegExp replace instead.
Bench result:
Bench result on main:
let me know if you want any changes. i'm not so happy about the amount of new consts lying around, but figured it is simpler than having some set of pairs i iterate through.
also @juliangruber, would you ever consider doing patches to 2.x? many millions of the downloads are still CJS (2.x), it would be good to get this perf gain out to them since they're unlikely to move to ESM sooner