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

perf: optimize scoped ID for light/native #4399

Merged
merged 4 commits into from
Jul 25, 2024
Merged

Conversation

nolanlawson
Copy link
Collaborator

@nolanlawson nolanlawson commented Jul 23, 2024

Details

Fixes #3658.

This avoids rendering the genScopedId function (aka gid aka global ID) or scopedFragId (aka fid aka fragment ID) for light DOM templates or shadow DOM templates when disableSyntheticShadowSupport is true. These functions only do anything in synthetic shadow DOM mode:

if (shadowMode === ShadowMode.Synthetic) {
return StringReplace.call(id, /\S+/g, (id) => `${id}-${idx}`);
}

if (shadowMode === ShadowMode.Synthetic && /^#/.test(url)) {
return `${url}-${idx}`;
}

None of our existing benchmarks are able to suss out the perf improvement. I did write a benchmark (nolanlawson@1599b49) which demonstrates the improvement, but I felt it was too tailored to this PR to make sense to commit to master. Here is the improvement (6-9%):

Screenshot 2024-07-23 at 8 39 55 AM

Here is a before-and-after to show what the compiled template looks like before and after this change. Note that on the right, everything is moved into static HTML fragments:

Screenshot 2024-07-23 at 8 39 13 AM

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

Since the gid/fid functions only do anything in synthetic shadow DOM, disabling them for light DOM or native shadow should be un-observable.

@nolanlawson nolanlawson requested a review from a team as a code owner July 23, 2024 15:59
vmBeingRendered
);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got rid of these logErrors because they seemed pretty low-value (only logged in dev mode, should arguably be the job of accessibility tools like aXe, not LWC), and I couldn't think of a good way to maintain the dev-only logging when the optimization is in place.

@@ -135,6 +135,7 @@ jobs:
- run: API_VERSION=61 yarn sauce:ci
- run: API_VERSION=61 DISABLE_SYNTHETIC=1 yarn sauce:ci
- run: DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER=1 DISABLE_SYNTHETIC=1 yarn sauce:ci
- run: DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER=1 DISABLE_SYNTHETIC=1 DISABLE_STATIC_CONTENT_OPTIMIZATION=1 yarn sauce:ci
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just another case I think is worth testing, especially if we start actually shipping disableSyntheticShadowSupport=true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eagerly anticipating another chore(ci): rebalance karma tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You guessed it! It's imbalanced again. I wish GH had an easier way to do this. 🫠

@@ -135,6 +135,7 @@ jobs:
- run: API_VERSION=61 yarn sauce:ci
- run: API_VERSION=61 DISABLE_SYNTHETIC=1 yarn sauce:ci
- run: DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER=1 DISABLE_SYNTHETIC=1 yarn sauce:ci
- run: DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER=1 DISABLE_SYNTHETIC=1 DISABLE_STATIC_CONTENT_OPTIMIZATION=1 yarn sauce:ci
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eagerly anticipating another chore(ci): rebalance karma tests

@nolanlawson nolanlawson merged commit 750f557 into master Jul 25, 2024
11 checks passed
@nolanlawson nolanlawson deleted the nolan/optimize-scoped-id branch July 25, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

disableSyntheticShadowSupport/lightDOM should remove genScopedId compilation
3 participants