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: replace startsWith with === #12531

Merged
merged 1 commit into from Mar 22, 2023
Merged

Conversation

sun0day
Copy link
Member

@sun0day sun0day commented Mar 22, 2023

Description

This pr use str[0] === 'x' instead of str.startsWith('x') for better perf. We can prove that:

I also test the initial vite dev startup time five times with this repo before and after this PR

test(ms) 1st 2nd 3rd 4th 5th
before pr 2406 2314 2079 1914 1686
after pr 2305 2216 2025 1949 1565

It improves!

Additional context

I guess we can use str[str.length - 1] === 'x' rather than str.endsWith('x') too.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Mar 22, 2023

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

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Awesome! I didn't expect the perf diff of this change alone to be noticeable 🙌🏼
I think the endsWith is worth doing at least if it is in a hot path.

@patak-dev patak-dev merged commit 9cce026 into vitejs:main Mar 22, 2023
12 checks passed
@sun0day
Copy link
Member Author

sun0day commented Mar 22, 2023

Awesome! I didn't expect the perf diff of this change alone to be noticeable 🙌🏼 I think the endsWith is worth doing at least if it is in a hot path.

I will give it a shot.

@sun0day sun0day mentioned this pull request Mar 22, 2023
9 tasks
@btea btea mentioned this pull request Jul 31, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants