kybarg / react-qr-scanner

React component for reading QR codes using PC web camera or mobile phone camera.
MIT License
126 stars 40 forks source link

10mb unpacked size on published 1.0.0-alpha.7? #46

Closed Zazzzles closed 2 years ago

Zazzzles commented 3 years ago

Seems like the lib is not correctly packaged on 1.0.0-alpha.7 since the bundle size is 10mb. Not sure if peer deps were added correctly. Seems fine on 1.0.0-alpha.5.

Indigo744 commented 3 years ago

I can confirm this issue:

barthicus commented 3 years ago

For the users that will come here to find out the reason app crashed during the build with the error HookWebpackError: Maximum call stack size exceeded - you need to downgrade to 1.0.0-alpha.5.

@Zazzzles @Indigo744 Thanks for your suggestions guys. I got random crashed when I was building the app with the next build command without any suggestions what was wring (only the general webpack error I mentioned earlier). After spending half of the day cutting out random pieces of code I find out that this library was causing this error. For me it was 1.0.0-alpha.7 version.

After I downgraded the plugin the lib size is smaller and no more failed builds.

BTW There were no errors in developer mode (command next).

itsdevcoffee commented 3 years ago

Does anyone know why alpha.7 is so massive? Even 1mb seems rather large for what it's doing.

Uzlopak commented 2 years ago

It seems, that the code is optimized for instantiating a webworker to handle the QR-Code reading. Idk if this is the way to go or because it makes it possible to make it more performant/run in parallel? It is a crazy big base64 encoded string, so it adds up to 30% additional data for the encoding.

@kybarg Anyhow... it has also alot of garbage data at the end of the base64 encode string. I checked it with a virus scanner, and got VEX.Webshell by Bkav Pro. Most sources say, that Bkav pro has a very aggressive heuristic. So the result was inconclusive.

It seemed that it is a 3.7 mb big memory dump at the end of the file. But also if I just check that binary data by virustotal, bkav pro does not say it is VEX.Webshell.

So I dug deeper and it seems that it is because of rollup-plugin-web-worker-loader. So I went through the PRs and found https://github.com/darionco/rollup-plugin-web-worker-loader/pull/45 . So I assumed that garbage code at the end is the source map.

So to check I set manually sourcemap: false as configuration option for the web-worker-loader. Voilá, the garbage is gone. So it was definetly the sourcemap. The resulting files are now each 1.7 mb and not bulky 5 mb.

So there are two solutions:

a. Upgrade rollup-plugin-web-worker-loader to the latest version. b. set manually sourcemap to false in rollup.config.js

kybarg commented 2 years ago

@Uzlopak wow, thank you very much for such a deep invetigation. Gonna fix this ASAP. Seems like a big flaw

kybarg commented 2 years ago

1.0.0-alpha.8 is released