-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Asset module binary files are stored in webpack cache #19359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Knagis I think we can implement |
right |
@alexander-akait that would be helpful, we originally started the patch by skipping worker-loader that kept invalidating cache on every build, then lazy-compilation-proxy and few plugins. So being able to do that within configuration would be appreciated. however for asset binaries - in my opinion, storing them in cache is something that should be skipped by default. Reading the much larger cache files in extreme (my) cases take more time than the asset module creation from scratch, but even in smaller cases, the asset modules have very little overhead, compared to things like babel/ts/css etc. I am not sure, but just in case - how are asset modules checking if the cache is up to date? Reading modification time or reading the contents to compare hash? |
We compare hashes. I don't think by default we should not cache assets modules - image minification/transformation are very expensive processes, so if you have cache, let's use it. I am with a new option and don't plan to change default behavior. |
But wouldn't that be the minification plugin that would write that cache entry, not asset module itself? We are not using it, but I assume the asset source gets cached, then the plugin caches and in the end the output gets cached as well? |
@Knagis It varies, and depends on what hook is using and how is doing it, I don't think that we should exclude some modules from the cache for some reason or another, this should definitely be configured by the developers, and for the entire time of the cache's existence, as you can see, this is the first problem regarding the size, I think that this is an exotic situation than the usual |
consider the simple example:
and single index.js
now if image.png and image2.png each are 1MB in size, the resulting cache pack is 4 MB - each of the asset files is stored twice in there. while it is true that cached build then only does While the proposed option to provide callback for caching would work for me, it isn't exactly straight forward to use - if you look at giving the dev easy control, then perhaps something like |
Yes, because we store original asset and generated
Theoretically we can implement it, but if some plugin will use cache, it will be cached anyway, because cache logic on developers side |
Bug report
Currently asset modules are stored in webpack filesystem cache, seemingly multiple times per asset, increasing the cache size significantly.
What is the current behavior?
Asset modules are cached in cache packs, seems both by the asset parser and then when dumping the compilation generated assets. In our large production build, webpack cache takes ~17GB.
We added the following patch in IdleFileCachePlugin.js and the cache size dropped to 1.8GB and cached build times improved.
If the current behavior is a bug, please provide the steps to reproduce.
Enable filesystem cache, configure asset/resource modules.
What is the expected behavior?
Asset module binary data is not stored in cache. Perhaps add a size limit to allow caching (just an example) 2KB assets, but nothing bigger. Reading the asset from disk directly would be as fast as reading it from the cache.
Other relevant information:
webpack version: 5.97.1
Node.js version: 23.8.0
Operating System: Win11
Additional tools:
The text was updated successfully, but these errors were encountered: