rxjs-autorun icon indicating copy to clipboard operation
rxjs-autorun copied to clipboard

Investigate tree-shaking compatibility

Open kosich opened this issue 4 years ago • 2 comments

As reported by @loreanvictor in #1, tree shaking might not be compatible with exporting $ and _ that share context variable with the computed fn.

Needs investigation.

kosich avatar Oct 16 '20 20:10 kosich

I had a quick look (I was on the train so couldn't do more atm). From a first glance on an actual project bundled with webpack (default config, no particular optimization), rxjs-autorun seems to add ~12KB to the bundle size (rxjs itself adds about the same, nothing in particular imported from it). Inspecting the bundle (manually, not with a tool) indicates that no unused code is imported from rxjs though, so I am not sure if this is directly related to tree-shaking or not.

For comparison, I used callbag-subject and callbag-expr, which together contributed ~1.5KB to the bundle. I will create an equivalent package for rxjs-autorun mirroring implementation of callbag-expr, investigate its contribution to bundle size, and see where are the deficits. Note that I am not sure by any means whether this bundle size increase is due to problematic tree-shaking or is it due to other factors.

loreanvictor avatar Oct 19 '20 08:10 loreanvictor

Thanks for looking into this! I haven't yet debugged tree-shaking and am not sure how to do it properly.

I suspect, that RxJS imports are already optimized since we directly import the operators/constructors that are well-separated. So the tree-shaking won't be that obvious here.

If you're right and we aren't side-effect free, then I'm lying in package.json — something to be properly set after the investigation (I accidentally copy-pasted that with project set-up 🙂). Also, maybe setting it to false would mark only this package out of tree-shaking and still let others to be stripped.

Should be relatively easy to check our tree-shaking: just import only the autorun, shake it, and see what code is left in the bundle (do we have _$, context and computed?)

kosich avatar Oct 19 '20 11:10 kosich