fix: replace regex used to split ranges#434
Merged
lukekarrys merged 1 commit intomainfrom Mar 25, 2022
Merged
Conversation
Found in #433, the regex used to split ranges on `||` was padded by `\s*` on either side causing a decrease in performance when used on range strings with a lot of spaces. Since the result of the split is immediately trimmed, we can just split on the string instead.
Contributor
Author
|
I ran some benchmarks locally using the following script which passes different arguments to const Range = require('./classes/range')
const a = process.argv.slice(2)
const s = ' '.repeat(Number(a[0]))
const r = `${s}1.1.1${s}`
const v = `${r}||${r}`.repeat(Number(a[1]))
const split = ({
poly: /\s*\|\|\s*/,
regex: /\|\|/,
string: '||',
})[a[2]]
new Range(v, {}, split)5 spaces x 10 versions 100 spaces x 100 versions 1000 spaces x 1000 versions |
lukekarrys
added a commit
that referenced
this pull request
Feb 26, 2022
This adds `@npmcli/template-oss` to manage GitHub Actions, linting, and other chores. It specifically pins to the latest version of the library in order to allow for the following manual changes: - Files outside of `lib/` to avoid breaking public API - Keeping engines (and testing) on `>=10` - Installs `npm@7` in CI to work with node 10 This surfaced a few bugs which I opted to fix in separate issues: - #432 - #434
lukekarrys
added a commit
that referenced
this pull request
Mar 23, 2022
This adds `@npmcli/template-oss` to manage GitHub Actions, linting, and other chores. It specifically pins to the latest version of the library in order to allow for the following manual changes: - Files outside of `lib/` to avoid breaking public API - Keeping engines (and testing) on `>=10` - Installs `npm@7` in CI to work with node 10 This surfaced a few bugs which I opted to fix in separate issues: - #432 - #434
lukekarrys
added a commit
that referenced
this pull request
Mar 25, 2022
This adds `@npmcli/template-oss` to manage GitHub Actions, linting, and other chores. It specifically pins to the latest version of the library in order to allow for the following manual changes: - Files outside of `lib/` to avoid breaking public API - Keeping engines (and testing) on `>=10` - Installs `npm@7` in CI to work with node 10 This surfaced a few bugs which I opted to fix in separate issues: - #432 - #434
nlf
approved these changes
Mar 25, 2022
Contributor
nlf
left a comment
There was a problem hiding this comment.
this is very clearly correct 👍
lukekarrys
added a commit
that referenced
this pull request
Mar 25, 2022
Found in #433, the regex used to split ranges on `||` was padded by `\s*` on either side causing a decrease in performance when used on range strings with a lot of spaces. Since the result of the split is immediately trimmed, we can just split on the string instead.
lukekarrys
added a commit
that referenced
this pull request
Mar 25, 2022
Found in #433, the regex used to split ranges on `||` was padded by `\s*` on either side causing a decrease in performance when used on range strings with a lot of spaces. Since the result of the split is immediately trimmed, we can just split on the string instead.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found in #433, the regex used to split ranges on
||was padded by\s*on either side causing a decrease in performance when used on range
strings with a lot of spaces. Since the result of the split is
immediately trimmed, we can just split on the string instead.