-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
perf: more regex improvements #12520
Conversation
Run & review this pull request in StackBlitz Codeflow. |
packages/vite/src/node/utils.ts
Outdated
@@ -1222,6 +1234,10 @@ export function joinUrlSegments(a: string, b: string): string { | |||
return a + b | |||
} | |||
|
|||
export function initialSlashRemoved(str: string): string { | |||
return str.startsWith('/') ? str.slice(1) : str |
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.
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.
That's interesting, I think we used startsWith
in quite a few other places too (and I usually use that). Do you have a link to the benchmark?
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.
Quite a big diff... changed here. @sun0day maybe you could change this in other places in another PR if you would like.
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 saw sapphi-red mentioned this link in another pr.
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.
The URL changes when you do a test in perf.link so you can share that directly instead (or with) the screenshot so others can continue playing and running it on their machines too.
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.
===
should be faster according to startsWith
source in theory
perf test data[0] === 'x'
wins most of the time
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.
LOVE the site! Let's go with [0] === '/'
then. It would be good to change this in other places like patak mentioned.
Description
Some more regex work (I think most is covered now). There are a few utils abstracted that we used in a few places too.
What is the purpose of this pull request?