react-refresh-webpack-plugin
react-refresh-webpack-plugin copied to clipboard
Fix injectRefreshLoader performance issue
After investigating some performance issues that only appear when enabling this plugin, I discovered that the require.resolve('react-refresh') which gets called in injectRefreshLoader seems to be the cause.
Moving the call outside the injectRefreshLoader cuts initial compile time in more than half (~40s -> ~15s) and incremental compile time has a similar speedup (~8s -> ~3s).
I don't know why, but I guess the require.resolve is not cached for some reason, or just takes some time, which adds up when the function runs for thousands of modules?
The change moving the refreshUtilsPath outside the function is not required to improve the performance, but I don't see why it wouldn't be moved outside the function as it should be static.
Tested on two different machines running the same project. May or may not address this issue: https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/543
@pmmmwh Please let me know if you need any additional information to get this merged!
Thanks!
@pmmmwh Can you release a new version for this change?
Thank!
Any idea on why require.resolve is not cached 🤔
Released.