You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Module parsed size counts UTF-16 characters, not bytes, so non-ASCII modules look smaller (even smaller than their gzip size) #749
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.
// src/index.mjsimport{zh}from"./zh.mjs";import("./lazy.mjs").then(m=>console.log(m.default,zh));// src/zh.mjsexportconstzh={title: "欢迎使用我们的应用程序",save: "保存更改",cancel: "取消操作",error: "发生了未知错误,请稍后重试"};// src/lazy.mjsexportdefault{ja: "ようこそ、アプリケーションへ。変更を保存しますか?",en: "Welcome to the application. Save changes?"};
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.
Activity
fix: count module and folder parsed sizes in UTF-8 bytes
fix: count module and folder parsed sizes in UTF-8 bytes
fix: count module and folder parsed sizes in UTF-8 bytes (webpack#750)