Skip to content

smarter function eval/inline #15

Activity

  1. changed the title [-]smarter function eval [/-] [+]smarter function eval/inline[/+] on Oct 10, 2024
  2. IWANABETHATGUY commented on Oct 10, 2024

    @IWANABETHATGUY
    Author

    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.

  3. kermanx commented on Oct 10, 2024

    @kermanx
    Owner

    Currently, there is a max_simple_string_length config, 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 span width 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 use unique_name instead.

    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.

  4. kermanx commented on Nov 22, 2024

    @kermanx
    Owner

    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🤔

  5. IWANABETHATGUY commented on Nov 22, 2024

    @IWANABETHATGUY
    Author

    Yeah, this issue just found when I tried to use tree-shaker, if the improvement is trivial, maybe we should skip this optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions