-
Notifications
You must be signed in to change notification settings - Fork 492
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
fix: optimistic parse #541
Conversation
@jakebailey Do you have some thoughts on this since you already had some experience benchmarking PNPM? |
if (!r.test(version)) { | ||
return null | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what the SemVer
constructor is doing. As you can see it's not even consistent with this code in that SemVer
trim()
s the version.
const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL])
if (!m) {
throw new TypeError(`Invalid Version: ${version}`)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why I removed it, the idea in that test is just to fail-fast.
So, can we consider that a bug or we could try to push this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's evidence in favor of this change. We don't need to optimize for bad semver here, and this PR is also a code cleanup and consistency issue.
Testing on pnpm, I don't see much difference, which doesn't surprise me given pnpm doesn't really call FWIW, if you want to test the big pnpm DT case, here are some instructions:
Then to do timing + memory stats, I have a #!/usr/bin/zsh
if [[ `uname` == Darwin ]]; then
MAX_MEMORY_UNITS=KB
else
MAX_MEMORY_UNITS=MB
fi
TIMEFMT=\
'total time: %E'$'\n'\
'user time: %U'$'\n'\
'system time: %S'$'\n'\
'CPU percent: %P'$'\n'\
'max memory: %M '$MAX_MEMORY_UNITS''$'\n'
time $@ So you can do |
I saw these lines that check if the version is valid and I thought, what if we remove it?
node-semver/functions/parse.js
Lines 21 to 24 in f66cc45
Well, the perf before:
Then:
It massive slowdown the invalid cases because
Semver
throws a exception (which is very slow) and then return null.But for optimistic cases, we can see a very good speedup.
If we combine this optimization with
parseOptions
, from:We speedup up to:
The main question is, how often PNPM and NPM see bad package versions?
References
benchmark.js