react-refresh-webpack-plugin icon indicating copy to clipboard operation
react-refresh-webpack-plugin copied to clipboard

Fix injectRefreshLoader performance issue

Open marco2216 opened this issue 3 years ago • 1 comments

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

marco2216 avatar Sep 01 '22 14:09 marco2216

@pmmmwh Please let me know if you need any additional information to get this merged!

marco2216 avatar Sep 02 '22 08:09 marco2216

Thanks!

pmmmwh avatar Sep 26 '22 01:09 pmmmwh

@pmmmwh Can you release a new version for this change?

Thank!

chenjiahan avatar Sep 27 '22 08:09 chenjiahan

Any idea on why require.resolve is not cached 🤔

JSerFeng avatar Sep 27 '22 14:09 JSerFeng

Released.

pmmmwh avatar Oct 09 '22 21:10 pmmmwh