rxjs-autorun
rxjs-autorun copied to clipboard
Investigate tree-shaking compatibility
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.
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.
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
?)