chore: improve tree shaking with pure annotations#1501
Conversation
|
Hi @Gravitonic, super interesting findings, thanks for this PR! I was under the impression that |
|
Honestly I'm not completely sure, but here's what I could figure out from my experiments and from what I could find in bundler documentation. It seems like
or the Webpack documentation:
That seems to makes sense with esbuild's metadata; here's why esbuild reports why it currently bundles
Even though the statement with the HTML decoding data is not used, the file is technically imported, and |
|
That makes sense, yes. Prettier is currently unhappy (likely the removed trailing comma in the type annotation), but otherwise I'm happy to merge this |
|
Thanks for this awesome PR @Gravitonic! |
|
Ah, sorry I got busy during the week — thanks! |
Not sure if this is desired, but by adding some more
/* #__PURE__ */function annotations, I was able to reduce bundle sizes, particularly for use cases only involving XML, since it enables bundlers to tree-shake out the HTML decoding trie. I've tested the tree-shaking behavior with esbuild and Rollup and put the results into a gist here. I've disabled minification for readability, so the file sizes are a bit larger, but I think the relative reductions should be comparable; in this simple case it's ~78% for Rollup and ~82% for esbuild but of course those figures would vary depending on usage.