Skip to content
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

Merged
merged 3 commits into from Mar 22, 2023
Merged

perf: more regex improvements #12520

merged 3 commits into from Mar 22, 2023

Conversation

patak-dev
Copy link
Member

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?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@stackblitz
Copy link

stackblitz bot commented Mar 21, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev added the performance Performance related enhancement label Mar 21, 2023
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str[0] === '/' ?

image

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://perf.link/

I saw sapphi-red mentioned this link in another pr.

Copy link
Member Author

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.

Copy link
Member

@sun0day sun0day Mar 22, 2023

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

Copy link
Member

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.

@patak-dev patak-dev merged commit abf536f into main Mar 22, 2023
18 checks passed
@patak-dev patak-dev deleted the perf/more-regex-improvements branch March 22, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance related enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants