plugins
plugins copied to clipboard
perf(pluginutils): optimize `createFilter` and `normalizePath`
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-codedwin32.sepandposix.sep. This is because this is faster, and the behavior ofnormalizePathshould 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.