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

gzip size of modules should be calculated in bulk #177

Closed
connorjclark opened this issue Mar 18, 2020 · 2 comments
Closed

gzip size of modules should be calculated in bulk #177

connorjclark opened this issue Mar 18, 2020 · 2 comments
Labels

Comments

@connorjclark
Copy link

connorjclark commented Mar 18, 2020

impl:

const getSize = options.gzip ? gzipSize.sync : Buffer.byteLength;
mappingRanges.forEach((lineRanges, lineIndex) => {
const line = lines[lineIndex];
const mergedRanges = mergeRanges(lineRanges);
mergedRanges.forEach(({ start, end, source }) => {
const rangeString = line.substring(start, end + 1);
const rangeByteLength = getSize(rangeString);
if (!files[source]) {
files[source] = { size: 0 };
}
files[source].size += rangeByteLength;

My concern is that calculating the gzip size of each mapping in isolation misses out on compression savings from common patterns. I expect this means that --gzip overestimates the gzip size of each module. Though I'm not sure what mergeRanges does, perhaps it is grouping everything?

(came up in GoogleChrome/lighthouse#10476)

@nikolay-borzov
Copy link
Collaborator

I expected this kind of issue. Getting 100% precise module gzip size seems almost impossible - a module is just part of a file. And gzip applies to the whole file. I still wonder what use of knowing the gzip size of a module when it's bundled with other modules.
Merging range purpose is to collect the biggest string that is part of a module. I haven't tested it enough but I think in most cases it should include the whole module code.
You can see actual bundle gzip size in totalBytes property

@connorjclark
Copy link
Author

I still wonder what use of knowing the gzip size of a module when it's bundled with other modules.

Our specific use case is we want to minify the download time for a bundle. Because of gzip, a large JSON module is probably fewer bytes than an equivalently sized JS module. It's nice to get a rough sense (understanding that exact numbers are impossible) so that we know where to invest engineering effort.

Merging range purpose is to collect the biggest string that is part of a module. I haven't tested it enough but I think in most cases it should include the whole module code.

if this is true then I think this tool is close enough. I see a comment saying it combines continuous mappings of the same source - but I think mappings tend to be continuous for an entire module so that sounds good to me.

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

No branches or pull requests

2 participants