plugins icon indicating copy to clipboard operation
plugins copied to clipboard

perf(pluginutils): optimize `createFilter` and `normalizePath`

Open kermanx opened this issue 1 year ago • 0 comments

Rollup Plugin Name: {pluginutils}

This PR contains:

  • [ ] bugfix
  • [ ] feature
  • [x] refactor
  • [ ] documentation
  • [ ] other

Are tests included?

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

Breaking Changes?

  • [ ] yes (breaking changes will not be merged unless absolutely necessary)
  • [x] 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 avatar Jul 24 '24 10:07 kermanx