case-sensitive-paths-webpack-plugin
case-sensitive-paths-webpack-plugin copied to clipboard
Speed improvements
Hey,
I ran some benchmarks on my webpack config and I saw that this plugin takes a significant time. After trying some rewrites and optimizations,I brought a 7-8 seconds build down to 5-6 seconds through the following speed improvements:
- Using Promises. This gives us ~1 seconds. Promises were added in Nodejs v4, so no breaking changes.
- Using Maps for caching. If the pathCache caches promises (Map<string, Promise<string[]) you can avoid concurrent
fs.readDir
for the same path. - Not doing recursive parent path reads. I see no point in doing this.
- Adding a configurable ignore path. There's no point in checking
node_modules
, for example.
All in all, this brings 1200+ directory reads down to ~400. I also rewrote the package in Typescript to avoid any type bugs.
I can submit all improvements as separate PRs (for easier reviewing). Would you be interested in merging them?
Hi there! I'd definitely love to see the use of promises - Originally this was written to support back to Node 4, but at this point even 8 is out of maintenance so I see no reason not to support native promises.
If you can improve caching too, by all means, and adding an ignore path makes sense. Not the first time that has come up.
As for the recursive parent path reads, that's actually intentional. Those calls are how this plugin checks the case on each directory in the path. Without them, you could get into a situation where a directory has the wrong case. Looking at the tests, I think I might not have actually written a test case for that, so even if you ran the tests I suspect this still might be a problem. I'll take a look at adding additional tests.
As for Typescript, I appreciate the effort but don't use it myself - rewriting to Typescript could make any future maintenance tasks for me harder.
FYI I just added a new test which should verify that nested folder names are being caught. If you're going to take a further look at recursive parent reads, make sure this new test passes.
👋 Would it be possible to get a release for the latest changes that got merged @Urthen? 🙂