Skip to content

Module parsed size counts UTF-16 characters, not bytes, so non-ASCII modules look smaller (even smaller than their gzip size) #749

Closed

Description

@trackoor

The parsed size of each module is computed as src.length (the number of UTF-16 code units), while the parsed size of the whole asset is Buffer.byteLength(src). For a module whose code contains non-ASCII text (translations, emoji data, CJK strings), the reported module parsed size is too small, by up to 3x for CJK text, and can even be smaller than the module's own gzip size.

Reproduction (webpack 5.112.2, webpack-bundle-analyzer 5.4.2, Node v26.13.0):

// src/index.mjs
import { zh } from "./zh.mjs";
import("./lazy.mjs").then(m => console.log(m.default, zh));

// src/zh.mjs
export const zh = { title: "欢迎使用我们的应用程序", save: "保存更改", cancel: "取消操作", error: "发生了未知错误,请稍后重试" };

// src/lazy.mjs
export default { ja: "ようこそ、アプリケーションへ。変更を保存しますか?", en: "Welcome to the application. Save changes?" };
// webpack.config.js
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
module.exports = {
  mode: "production",
  entry: "./src/index.mjs",
  optimization: { concatenateModules: false },
  plugins: [new BundleAnalyzerPlugin({ analyzerMode: "json", reportFilename: "report.json", openAnalyzer: false })],
};

Run npx webpack, then inspect dist/report.json:

main.js         parsedSize=2889  (file is 2889 bytes)
  src/zh.mjs    parsedSize=94    gzipSize=181
598.js          parsedSize=252   (file is 252 bytes)
  src/lazy.mjs  parsedSize=109   gzipSize=182

The module source that parseBundle extracts for lazy.mjs is 109 characters but 159 UTF-8 bytes, and for zh.mjs 94 characters but 158 UTF-8 bytes. Expected parsedSize is 159 and 158. Because gzipSize is computed from the UTF-8 bytes while parsedSize counts UTF-16 code units, parsedSize is reported as smaller than gzipSize.

Tested on webpack-bundle-analyzer 5.4.2 and main (622f27d3). The cause is getParsedSize() in src/tree/Module.js returning this.src.length (and parsedSize in src/tree/Folder.js doing the same); #223 changed the asset size in src/analyzer.js to Buffer.byteLength but left Module and Folder using .length.

Credit: https://ucsbplse.github.io/

Activity

  1. added 2 commits that reference this issue on Nov 8, 2026
    713a498
    411ad86
  2. added a commit that references this issue on Nov 8, 2026
    cec6ac6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions