dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

dart2js: reduce unminified names in .js files #25003

Open rakudrama opened 8 years ago

rakudrama commented 8 years ago

There are some common unminified properties in minified code.

Quick analysis of potential savings of an Angular2 + Dart app (compiled with --fast-startup)

Minify $requiredArgCount, $defaultValues, $signature: 1.64% Minify inherit and installTearOff: 1.66%

Replace most common $signature with references to shared function: 1.5% 171 $signature:function(){return{func:1,args:[,,]}} 180 $signature:function(){return{func:1}} 415 $signature:function(){return{func:1,args:[,]}}

Replace most common $defaultValues:function(){return[]} with reference to shared function: 0.62%

Hopefully references to a shared function would parse faster than functions.

That is 3.3% with simply minifying helper function names and 5.4% with some other simple tricks. I don't expect that the gzipped file will be smaller. Subtract 1.66% for the standard emitter.

joseluis commented 8 years ago

I was just going to open an issue about this. There do seems to be still a lot of room for minification.

I'm currently using UglifyJS to further minify the JavaScript code already minified with dart2js, and reducing its size by an additional 10%.

You can see an example comparison here: https://gist.github.com/joseluis/e2c3c21d72e411d78d6d

rakudrama commented 8 years ago

Additional thing: the static: property is not minified.

rakudrama commented 7 years ago

These changes help with some of the --fast-startup issues: https://github.com/dart-lang/sdk/commit/cdba92a563128bb4febcdf94270b761c23401067 - shares $defaultValues via common base class https://github.com/dart-lang/sdk/commit/0c83262a1e4d0977a2fd3f77202c6b358221b23c - shorter names for $requiredArgCount, $defaultValues, $signature.

Still to do: