Skip to content

“Serializing big strings” warning with Webpack 5 filesystem cache #643

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

Closed
andersk opened this issue Nov 1, 2020 · 5 comments · Fixed by #647
Closed

“Serializing big strings” warning with Webpack 5 filesystem cache #643

andersk opened this issue Nov 1, 2020 · 5 comments · Fixed by #647

Comments

@andersk
Copy link

andersk commented Nov 1, 2020

  • Operating System: Linux
  • Node Version: 14.14.0
  • NPM Version: 6.14.8
  • webpack Version: 5.3.2
  • mini-css-extract-plugin Version: 1.2.1

Expected Behavior

No warnings.

Actual Behavior

When using Webpack 5 with cache: { type: "filesystem" }, mini-css-extract-plugin triggers this warning on sufficiently large CSS files: <w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (194kiB) impacts deserialization performance (consider using Buffer instead and decode when needed).

Code

// webpack.config.js
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  cache: { type: "filesystem" },
  entry: "bootstrap/dist/css/bootstrap.css",
  module: {
    rules: [
      { test: /\.css$/, use: [MiniCssExtractPlugin.loader, "css-loader"] },
    ],
  },
  plugins: [new MiniCssExtractPlugin()],
};

How Do We Reproduce?

$ npm i bootstrap css-loader mini-css-extract-plugin webpack webpack-cli

+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
added 194 packages from 170 contributors, removed 157 packages, updated 6 packages and audited 201 packages in 7.192s

$ rm -rf .cache node_modules/.cache  # needed to reproduce more than once
$ npx webpack
[webpack-cli] Compilation finished
<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (194kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
asset main.css 194 KiB [compared for emit] (name: main)
asset main.js 0 bytes [compared for emit] [minimized] (name: main)
Entrypoint main 194 KiB = main.css 194 KiB main.js 0 bytes
./node_modules/bootstrap/dist/css/bootstrap.css 50 bytes [built] [code generated]
css ./node_modules/css-loader/dist/cjs.js!./node_modules/bootstrap/dist/css/bootstrap.css 194 KiB [code generated]
webpack 5.3.2 compiled successfully in 468 ms
@sokra
Copy link
Member

sokra commented Nov 1, 2020

Add infrastructureLogging.debug: /PackFileCache/ to get a stack trace

@andersk
Copy link
Author

andersk commented Nov 1, 2020

@sokra That gave me more messages but no stack trace.

$ npx webpack
    [webpack.cache.PackFileCacheStrategy] No pack exists at /tmp/test/.cache/webpack/default-production.pack: Error: ENOENT: no such file or directory, open '/tmp/test/.cache/webpack/default-production/index.pack'
<t> [webpack.cache.PackFileCacheStrategy] restore cache container: 21.607204 ms
[webpack-cli] Compilation finished
    [webpack.cache.PackFileCacheStrategy] Pack got invalid because of write to: ResolverCachePlugin|normal|dependencyType=|esm|path=|/tmp/test|request=|bootstrap/dist/css/bootstrap.css
    [webpack.cache.PackFileCacheStrategy] Storing pack...
    [webpack.cache.PackFileCacheStrategy] Capturing build dependencies... (/tmp/test/node_modules/webpack/lib/, /tmp/test/node_modules/css-loader/dist/cjs.js, /tmp/test/node_modules/mini-css-extract-plugin/dist/loader.js)
<t> [webpack.cache.PackFileCacheStrategy] resolve build dependencies: 448.126612 ms
<t> [webpack.cache.PackFileCacheStrategy] snapshot build dependencies: 18.92186 ms
    [webpack.cache.PackFileCacheStrategy] Captured build dependencies
    [webpack.cache.PackFileCacheStrategy] 20 fresh items in cache
<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (194kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
<t> [webpack.cache.PackFileCacheStrategy] store pack: 23.432643 ms
    [webpack.cache.PackFileCacheStrategy] Stored pack
asset main.css 194 KiB [emitted] (name: main)
asset main.js 0 bytes [emitted] [minimized] (name: main)
Entrypoint main 194 KiB = main.css 194 KiB main.js 0 bytes
./node_modules/bootstrap/dist/css/bootstrap.css 50 bytes [built] [code generated]
css ./node_modules/css-loader/dist/cjs.js!./node_modules/bootstrap/dist/css/bootstrap.css 194 KiB [code generated]
webpack 5.3.2 compiled successfully in 402 ms

However, by manually inserting a console.trace() into webpack/lib/serialization/ObjectMiddleware.js, I get

<w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (194kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
Trace
    at process (/tmp/test/node_modules/webpack/lib/serialization/ObjectMiddleware.js:387:14)
    at write (/tmp/test/node_modules/webpack/lib/serialization/ObjectMiddleware.js:299:6)
    at CssDependency.serialize (/tmp/test/node_modules/mini-css-extract-plugin/dist/CssDependency.js:42:5)
    at Object.serialize (/tmp/test/node_modules/mini-css-extract-plugin/dist/CssDependency.js:59:16)
    at process (/tmp/test/node_modules/webpack/lib/serialization/ObjectMiddleware.js:367:17)
    at write (/tmp/test/node_modules/webpack/lib/serialization/ObjectMiddleware.js:299:6)
    at ArraySerializer.serialize (/tmp/test/node_modules/webpack/lib/serialization/ArraySerializer.js:10:29)
    at process (/tmp/test/node_modules/webpack/lib/serialization/ObjectMiddleware.js:367:17)
    at write (/tmp/test/node_modules/webpack/lib/serialization/ObjectMiddleware.js:299:6)
    at NormalModule.serialize (/tmp/test/node_modules/webpack/lib/DependenciesBlock.js:83:3)

where mini-css-extract-plugin/dist/CssDependency.js:42 is the write(this.content); from mini-css-extract-plugin/src/CssDependency:32.

@alexander-akait
Copy link
Member

Thanks I think we can switch on buffer

@alexander-akait
Copy link
Member

@sokra what do you think?

@sokra
Copy link
Member

sokra commented Nov 2, 2020

Yep use a Buffer. Convert to buffer during parsing. Convert from buffer to string during code generation.

Parsing is only done once. Code generation will be skipped if the css output file doesn't change. This way no utf-8 conversion is needed, buffer never have to be decoded to a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants