Skip to content
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

Fix: use minified size in sourcemap mode #164

Closed
wants to merge 4 commits into from

Conversation

thoughtspile
Copy link

Hi @btd! As discussed yesterday in #163, fixed sourcemap mode to correctly measure module size after minification. To address your concern about surrogate pairs, I collect actual code in the final chunk per-module instead of incrementing renderedLength.

Since we now have the precise code available in sourcemap mode, I also went ahead and allowed gzipSize and brotliSize in sourcemap mode. Compressed sizes are very close to ones in default mode.

Added a test case with terser, updated snapshots for both changes. Un-minified sourcemap sizes are 1 byte larger than bundle.code[id] because rollup trims trailing newline.

I wonder if we could remove non-sourcemap option altogether? It doesn't seem to have any benefits, and reports incorrect sizes.

Fixes #163

@thoughtspile
Copy link
Author

Hi @btd , could you take a look?

@thoughtspile
Copy link
Author

Hey @btd, did you have a chance to look through the changes? It's not too complicated, and should greatly improve the analysis.

Copy link
Owner

@btd btd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for taking so long. Super busy at work.
Overall feedback: with your changes you remove support of old 2.x rollup. I still support it, next you silent and removed feedback about gzip,brotli options with sourcemap.

@@ -83,7 +83,6 @@ export interface PluginVisualizerOptions {

/**
* If plugin should use sourcemap to calculate sizes of modules. By idea it will present more accurate results.
* `gzipSize` and `brotliSize` does not make much sense with this option.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you removed this? You also disabled this in code.

const gzipSize = !!opts.gzipSize && !opts.sourcemap;
const brotliSize = !!opts.brotliSize && !opts.sourcemap;
const gzipSize = !!opts.gzipSize;
const brotliSize = !!opts.brotliSize;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would print a warning also. It is not good UX to just silently disable options.

code,
}: {
id: string;
renderedLength: number;
code: string | null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please return this back. It is to support old 2.x version of rollup

@@ -214,9 +211,8 @@ export const visualizer = (
const moduleRenderInfo = await Promise.all(
Object.values(modules)
.filter(({ id }) => filter(bundleId, id))
.map(({ id, renderedLength }) => {
const code = bundle.modules[id]?.code;
return ModuleLengths({ id, renderedLength, code });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above. Code was added only in the middle of 2.x (i support it)

@@ -225,7 +221,7 @@ export const visualizer = (
const modules = await Promise.all(
Object.entries(bundle.modules)
.filter(([id]) => filter(bundleId, id))
.map(([id, { renderedLength, code }]) => ModuleLengths({ id, renderedLength, code }))
.map(([id, { code }]) => ModuleLengths({ id, code: code || "" }))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above

modules[id] = modules[id] || { id, renderedLength: 0 };
modules[id].renderedLength += 1;
modules[id] = modules[id] || { id, code: "" };
modules[id].code += code[i];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to try to combine code there. gzip and brotli sizes disabled for it. To get length need to get code point and get its length as surrogate pair

rendered: 12
rendered: 13
gzip: 33
brotli: 17
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not make sense at all

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 this pull request may close these issues.

[BUG] Massive size mismatch for minified code
2 participants