Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate if (detaching) checks for components with multiple root elements #6684

Closed
K4rakara opened this issue Aug 26, 2021 · 2 comments
Closed
Labels

Comments

@K4rakara
Copy link

K4rakara commented Aug 26, 2021

Describe the bug

When creating a component with multiple root elements, Svelte currently checks detaching for every single root element. IE:

// Truncated for brevity, see REPL

// ...

function create_fragment(ctx) {
  // ...
  return {
    // ...
    d(detaching) {
      if (detaching) detach(h1);
      if (detaching) detach(t1);
      if (detaching) detach(h2);
      if (detaching) detach(t3);
      if (detaching) detach(h3);
    }
  };
}

// ...

When ran through Terser, that roughly becomes:

detaching && detach(h1),
detaching && detach(t1),
detaching && detach(h2),
detaching && detach(t2),
detaching && detach(h3);

This should be fairly simple to cut down to this:

if (detaching) {
  detach(h1);
  detach(t1);
  detach(h2);
  detach(t3);
  detach(h3);
}

... which roughly becomes this:

detaching && (
  detach(h1),
  detach(t1),
  detach(h2),
  detach(t3),
  detach(h3)
);

This is a really minor thing, but it should lead to slightly better bundle sizes for some users.

I'd be happy to fix this as a first pull request 😄

Reproduction

REPL

Logs

No response

System Info

I encountered this on the playground, so I suppose 3.42.3?

Severity

annoyance

@Conduitry Conduitry added the perf label Aug 26, 2021
@dummdidumm
Copy link
Member

Since this is a synchronous code path I'd say there's no reason to not tweak this, so you can go ahead and create a PR if you want to 👍

@gtm-nayan
Copy link
Contributor

#8763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants