vite-bundle-visualizer icon indicating copy to clipboard operation
vite-bundle-visualizer copied to clipboard

File sizes appear larger in visualizer than in reality

Open toBeOfUse opened this issue 2 years ago • 11 comments

The file sizes shown in the visualizer are larger than the ones reported by Vite on the command line or that show up on disk after building. To see this, you can just clone vitesse, install its packages, and run vite-bundle-visualizer for it.

On the command line, a file size of 153kb is shown for the main javascript asset:

image

Similarly, on disk, the file appears to be 150kb:

image

But in the visualizer, the same file (with the same hash in the name, so it should have the same contents) is reported to be 461kb:

image

toBeOfUse avatar Jul 25 '23 23:07 toBeOfUse

It seems like only happen in vitesse or vite-ssg project? Looking weird, I will try to figure it out.

KusStar avatar Jul 27 '23 10:07 KusStar

v0.10.0 involves --sourcemap option, it will more accurate but result less detailed.

image

KusStar avatar Jul 27 '23 10:07 KusStar

same problem for me!

real bundle size: image

same bundle in visualizer: image

with --sourcemap option: image

samosad avatar Aug 28 '23 12:08 samosad

The sourcemap option is indeed less detailed, and also not more accurate, in my experience. E.g. I separated out a lodash chunk to test it, and the build (and file system) show that chunk as 34.18 kB, whereas the sourcemap options shows it as 185.66 KB (which is 190.12 kB), so it's off by 5.5x. Another chunk, however measured 2.2x off.

This hurts the functional usefulness of the tool dramatically because the relative sizes of modules and chunks are not accurate. It wouldn't be such an issue if just the numbers were inaccurate, but with the relative sizing being so dramatically off, this tool is really only useful as a module graph.

Without the sourcemap option, the numbers appear identical, but there is gzip info at least.

Edit: Appears to match this issue. Since it's downstream, and I don't see anything wrong with this Vite wrapper code, there's probably not much the author can do. This plugin is already using the latest, and it doesn't appear to help.

bfricka avatar Aug 31 '23 23:08 bfricka

The sourcemap option is indeed less detailed, and also not more accurate, in my experience. E.g. I separated out a lodash chunk to test it, and the build (and file system) show that chunk as 34.18 kB, whereas the sourcemap options shows it as 185.66 KB (which is 190.12 kB), so it's off by 5.5x. Another chunk, however measured 2.2x off.

This hurts the functional usefulness of the tool dramatically because the relative sizes of modules and chunks are not accurate. It wouldn't be such an issue if just the numbers were inaccurate, but with the relative sizing being so dramatically off, this tool is really only useful as a module graph.

Without the sourcemap option, the numbers appear identical, but there is gzip info at least.

Edit: Appears to match this issue. Since it's downstream, and I don't see anything wrong with this Vite wrapper code, there's probably not much the author can do. This plugin is already using the latest, and it doesn't appear to help.

Yeah, it seems the output bundles information of Vite(internal is rollup) is inaccurate, you only can get accurate final size of a module bundle, which are tree-shaken results, but only get size of a module before tree-shaken in module graph. Result in inaccurate in some cases.

KusStar avatar Sep 01 '23 07:09 KusStar

@KusStar seems like this issue was fixed in rollup-plugin-visualizer, would you mind updating your package to the latest version? https://github.com/btd/rollup-plugin-visualizer/issues/163

stefan-schweiger avatar Sep 21 '23 11:09 stefan-schweiger

Oh sorry, just saw that you are already on this version :(

stefan-schweiger avatar Sep 21 '23 11:09 stefan-schweiger

Any workarounds for this issue? I'm seeing the same issue. When I visualize deps, it seems like it's not honoring build.rollupOptions.treeshake where was vite build does, rendering the actual usefulness of the visualization useless.

samesfahani-tuplehealth avatar Oct 23 '23 14:10 samesfahani-tuplehealth

Are there any updates? It's too hard to analyze deps if I can't trust the data (

gavrashenko avatar Nov 15 '23 11:11 gavrashenko

I've just noticed this problem too. It's not very useful if the sizes are all off.

SimonEast avatar May 09 '24 05:05 SimonEast