Repository navigation
smarter function eval/inline #15
Description
Activity
Interesting thing, terser has same strategy as
tree-shaker, they always inline function for this case.for
swc, it only inlines the function result when the function is called only once.Currently, there is a
max_simple_string_lengthconfig, strings longer than this value won't be inlined.I can also think of some other strategies:
- Option 1: Compare the literal's length to the
spanwidth of the node to be replaced - Option 2: If a string is going to be inlined multiple times, then append
var unique_name="ABCDE"at the end of the program and useunique_nameinstead.
And there is also a problem of
export function f() { effect() } export const x = f()
being tree-shaked into
export function f() { effect(); } export const x = (f(), undefined);
This is not hard to solve but will lead to more lines of code - every transform function should return whether the value is still reserved. Not sure if there is a better strategy.
- Option 1: Compare the literal's length to the
It seems that duplicating literals only has a very small effect on the gzipped size. And I found it cost a noticeable performance to avoid the duplication🤔
Yeah, this issue just found when I tried to use
tree-shaker, if the improvement is trivial, maybe we should skip this optimization.Reacted by _Kerman
https://kermanx.github.io/tree-shaker/#N4IglgdgDgrgLiAXCAZjCBjOYD2EAEcApgM5wAUAlPsADoH4BORcMjBtIAhj73153oBfeqMx4SOADZEAdFJwBzcsTLkAjJUr0ME6XIXLVFTdvERJM+UpWkTWnXquHba044v7rRuxofnLAxtjPzNdT2dg33cArxcQmPDA71d7MKcgnzd/JLio7LMxehAAGhAAExwAFWYiAGUACy4AayIkOEYYIjLKgFlIMBQATyQULikSIiEgA===
For this case, the optimized result is larger than the unoptimized version.