Faster minifier with swc and improved source maps

Today I released version 5 of zodern:standard-minifier-js.

This update makes it 3 - 7x faster than standard-minifier-js. It replaces terser with swc, and uses a faster js parser. It also switches to @zodern/source-maps for concatenating the files, which is 16x faster than the library previously used. The package size was also reduced, so it is faster to install.

A couple years ago I added caching to zodern:standard-minifier-js. With caching, it can be much faster, depending on what was changed since the last build.

A number of Meteor packages, especially core packages, don’t have source maps. I’m working on fixing this for Meteor 3, but in the meantime the minifier will now try to create source maps for these packages. It does this in both development and production.

You can try it in your app by running:

meteor remove standard-minifier-js
meteor add zodern:standard-minifier-js

It is compatible with Meteor 1.9 and newer.

13 Likes

It’s indeed much faster and also consumes less memory.

A zCloud client was having issues building their app with the previous version, it was not working at all for his case, it was breaking even with 10Gbs+ of memory.

Now with this new version it works flawlessly.

Thank you @zodern :rocket:

3 Likes

So when will this be replacing the current minifier?

The biggest issue blocking bringing the features over is that hiding production sourcemaps causes issues with cordova.

For the performance improvements, we can easily improve the parsing speed in the core minifier, which would save a few seconds for large apps. Switching to swc will be more difficult if we don’t want to drastically increase the size of the js minifier package (it would double from 50mb to 100mb) - I’m planning to at least partially fix this in Meteor 3. zodern:standard-minifier-js reduced the package size, but the way it did so wouldn’t be something we would want to do in a core package.

2 Likes

Awesome stuff @zodern, really cool to see! Will give it a try! :slight_smile:

Does this bundler also improve meteor build times? We are running our builds in a Github Action and would love to bring down this current ~5min build time a bit.

Thank you for your awesome work!

seriously … I had to visit a website after the upload just to make sure anything remained out of the bundle. It cannot be that fast … :slight_smile:

Very very well done!

1 Like

Yes, it does make meteor build faster. I wrote a blog post about optimizing CI, which has some other suggestions that could also help: Optimizing CI for Meteor

Moved my post to github instead: Error: Duplicate parameter 'e' not allowed in function with default parameter values. · Issue #38 · zodern/minify-js-sourcemaps · GitHub

Correcting my previous answer. zodern:standard-minifier-js might not be production ready. I added to @rjdavid Github ticket.

Lol where did this even come from? This is amazing god level programming. Improvements like this come rarely, so I’m pretty excited for this one.

1 Like

I am having problems with the handsontable package 12.x and later. In development it works while production generates the error

Uncaught (in promise) RangeError: Maximum call stack size exceeded
at nA (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:10452)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12213)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)
at ng.runSetters (d1066cae49cd7d45c71a7872fcf90d32e1eed066.js?meteor_js_resource=true:5:12570)

when importing the above library.

I noticed that if I use the syntax

import Handsontable from "handsontable"

it generates the error, whereas with the syntax:

import Handsontable from "handsontable/dist/handsontable.full.min".

It works.

For now I’m going back to the standard version, as I don’t want it to generate any more problems. Too bad because the possibility of avoiding the generation of statistics is very convenient.

https://x.com/sebastienlorber/status/1843269971364995139

1 Like