Open yanchith opened 5 years ago
I did some experiments with a really trivial hello world app (basically the triangle example), here are the build size results:
Without tree-shaking optimized API (current master
)
125k webglutenfree-app.prod.js
40k webglutenfree-app.prod.min.js
With tree-shaking optimized API (https://github.com/yanchith/webglutenfree/tree/tree-shakable-api)
84k webglutenfree-app-treeshake-opt.prod.js
28k webglutenfree-app-treeshake-opt.prod.min.js
The tree-shaking optimized version is roughly 67% to 70% of the current size, making this desirable to have.
Since the change would be a major API change and the new API would have to be either less straightforward (some operations would be functions, some methods), or less simple (making every operation a function would make it harder to tell which functions are associated with what data types), I won't pursue this for 0.1.0
, but may possibly revisit later.
Currently
rollup
does not attempt to prune class methods due to the dynamic nature of the language, and it seems that even if it did, it would have to be really conservative about it (https://github.com/rollup/rollup/issues/349). This means that our current API does not tree-shake well:Device
is a class with a lot of methods that utilize imports from the rest of the library.This is what the API could look like with plain functions:
We could potentially keep methods that don't make use of imports, or move everything into functions for more consistency.