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

fix(pluginutils): optimize createFilter and normalizePath #1750

Merged
merged 6 commits into from
Sep 23, 2024

Conversation

KermanX
Copy link
Contributor

@KermanX KermanX commented Jul 24, 2024

Rollup Plugin Name: {pluginutils}

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

Description

createFilter and normalizePath are on the hot path. This PR tries to improve their performance.

Simple benchmarks (may not be very accurate, but IMO the direction is right):

  • filename.split(win32.sep).join(posix.sep) -> filename.replace(/\\/g, '/') - jsbenchmark.com
    Also, this PR hard-coded win32.sep and posix.sep. This is because this is faster, and the behavior of normalizePath should not change even when one day Windows starts to use / as the path separator.
  • /\0/.test(id) -> id.includes('\0') - jsbenchmark.com

Also, this PR creates a fast path for empty filters - Usually createFilters takes paths from plugins' options, which defaults to empty if not specified.

@KermanX KermanX requested a review from shellscape as a code owner July 24, 2024 10:08
@shellscape shellscape changed the title perf(pluginutils): optimize createFilter and normalizePath fix(pluginutils): optimize createFilter and normalizePath Sep 22, 2024
@shellscape shellscape merged commit 87891d5 into rollup:master Sep 23, 2024
5 checks passed
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.

2 participants