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

[reactive-element] Adds preserveExisting option to adoptStyles #3060

Closed
wants to merge 11 commits into from

Conversation

sorvell
Copy link
Member

@sorvell sorvell commented Jun 17, 2022

Fixes #3010. Adds ability to add to an existing set of styles via adoptStyles.

Size delta:
main: 12.75 kB │ 6.49 kB │ 5.57 kB
preserve: 13.29 kB │ 6.73 kB │ 5.8 kB

justinfagnani and others added 3 commits June 1, 2022 08:16
@changeset-bot
Copy link

changeset-bot bot commented Jun 17, 2022

🦋 Changeset detected

Latest commit: 4cff378

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit/reactive-element Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jun 17, 2022

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -1% - +2% (-0.26ms - +0.45ms)
    this-change vs tip-of-tree

render

  • lit-element-list: 74.70ms - 75.60ms
  • lit-html-kitchen-sink: unsure 🔍 -1% - +1% (-0.17ms - +0.32ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -12% - +5% (-1.25ms - +0.59ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -0% - +2% (-0.17ms - +1.21ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +2% (-1.20ms - +1.37ms)
    this-change vs tip-of-tree

update

  • lit-element-list: 682.12ms - 690.58ms
  • lit-html-kitchen-sink: unsure 🔍 -1% - +5% (-0.98ms - +3.49ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -3% - +3% (-8.10ms - +8.26ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: slower ❌ 0% - 3% (0.21ms - 3.10ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -0% - +1% (-0.73ms - +9.72ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: 700.11ms - 707.90ms
  • reactive-element-list: unsure 🔍 -0% - +1% (-2.52ms - +9.82ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs
74.70ms - 75.60ms-

update

VersionAvg timevs
682.12ms - 690.58ms-

update-reflect

VersionAvg timevs
700.11ms - 707.90ms-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
27.17ms - 27.56ms-unsure 🔍
-1% - +1%
-0.17ms - +0.32ms
unsure 🔍
-1% - +1%
-0.32ms - +0.19ms
tip-of-tree
tip-of-tree
27.14ms - 27.43msunsure 🔍
-1% - +1%
-0.32ms - +0.17ms
-unsure 🔍
-1% - +0%
-0.36ms - +0.08ms
previous-release
previous-release
27.26ms - 27.59msunsure 🔍
-1% - +1%
-0.19ms - +0.32ms
unsure 🔍
-0% - +1%
-0.08ms - +0.36ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
76.54ms - 80.11ms-unsure 🔍
-1% - +5%
-0.98ms - +3.49ms
unsure 🔍
-2% - +3%
-1.75ms - +2.38ms
tip-of-tree
tip-of-tree
75.72ms - 78.43msunsure 🔍
-4% - +1%
-3.49ms - +0.98ms
-unsure 🔍
-3% - +1%
-2.64ms - +0.76ms
previous-release
previous-release
76.97ms - 79.05msunsure 🔍
-3% - +2%
-2.38ms - +1.75ms
unsure 🔍
-1% - +3%
-0.76ms - +2.64ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
23.60ms - 24.19ms-unsure 🔍
-1% - +2%
-0.26ms - +0.45ms
unsure 🔍
-1% - +2%
-0.30ms - +0.44ms
tip-of-tree
tip-of-tree
23.60ms - 23.99msunsure 🔍
-2% - +1%
-0.45ms - +0.26ms
-unsure 🔍
-1% - +1%
-0.32ms - +0.28ms
previous-release
previous-release
23.60ms - 24.04msunsure 🔍
-2% - +1%
-0.44ms - +0.30ms
unsure 🔍
-1% - +1%
-0.28ms - +0.32ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
10.05ms - 10.46ms-unsure 🔍
-12% - +5%
-1.25ms - +0.59ms
unsure 🔍
-2% - +3%
-0.20ms - +0.30ms
tip-of-tree
tip-of-tree
9.69ms - 11.48msunsure 🔍
-6% - +12%
-0.59ms - +1.25ms
-unsure 🔍
-5% - +13%
-0.53ms - +1.29ms
previous-release
previous-release
10.07ms - 10.35msunsure 🔍
-3% - +2%
-0.30ms - +0.20ms
unsure 🔍
-12% - +5%
-1.29ms - +0.53ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
262.77ms - 277.15ms-unsure 🔍
-3% - +3%
-8.10ms - +8.26ms
unsure 🔍
-6% - +3%
-15.97ms - +9.36ms
tip-of-tree
tip-of-tree
265.97ms - 273.79msunsure 🔍
-3% - +3%
-8.26ms - +8.10ms
-unsure 🔍
-5% - +3%
-14.52ms - +7.75ms
previous-release
previous-release
262.83ms - 283.69msunsure 🔍
-3% - +6%
-9.36ms - +15.97ms
unsure 🔍
-3% - +5%
-7.75ms - +14.52ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
52.43ms - 53.48ms-unsure 🔍
-0% - +2%
-0.17ms - +1.21ms
unsure 🔍
-1% - +2%
-0.47ms - +1.02ms
tip-of-tree
tip-of-tree
51.99ms - 52.89msunsure 🔍
-2% - +0%
-1.21ms - +0.17ms
-unsure 🔍
-2% - +1%
-0.94ms - +0.45ms
previous-release
previous-release
52.15ms - 53.21msunsure 🔍
-2% - +1%
-1.02ms - +0.47ms
unsure 🔍
-1% - +2%
-0.45ms - +0.94ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
112.43ms - 114.75ms-slower ❌
0% - 3%
0.21ms - 3.10ms
unsure 🔍
-0% - +2%
-0.52ms - +2.59ms
tip-of-tree
tip-of-tree
111.07ms - 112.80msfaster ✔
0% - 3%
0.21ms - 3.10ms
-unsure 🔍
-2% - +1%
-1.97ms - +0.73ms
previous-release
previous-release
111.51ms - 113.59msunsure 🔍
-2% - +0%
-2.59ms - +0.52ms
unsure 🔍
-1% - +2%
-0.73ms - +1.97ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
55.51ms - 56.99ms-unsure 🔍
-2% - +2%
-1.20ms - +1.37ms
unsure 🔍
-1% - +2%
-0.57ms - +1.27ms
tip-of-tree
tip-of-tree
55.11ms - 57.22msunsure 🔍
-2% - +2%
-1.37ms - +1.20ms
-unsure 🔍
-2% - +3%
-0.92ms - +1.45ms
previous-release
previous-release
55.36ms - 56.44msunsure 🔍
-2% - +1%
-1.27ms - +0.57ms
unsure 🔍
-3% - +2%
-1.45ms - +0.92ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
692.50ms - 700.11ms-unsure 🔍
-0% - +1%
-0.73ms - +9.72ms
unsure 🔍
-0% - +1%
-1.64ms - +9.04ms
tip-of-tree
tip-of-tree
688.22ms - 695.39msunsure 🔍
-1% - +0%
-9.72ms - +0.73ms
-unsure 🔍
-1% - +1%
-5.98ms - +4.39ms
previous-release
previous-release
688.85ms - 696.35msunsure 🔍
-1% - +0%
-9.04ms - +1.64ms
unsure 🔍
-1% - +1%
-4.39ms - +5.98ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
806.33ms - 815.62ms-unsure 🔍
-0% - +1%
-2.52ms - +9.82ms
unsure 🔍
-0% - +1%
-3.69ms - +8.59ms
tip-of-tree
tip-of-tree
803.26ms - 811.39msunsure 🔍
-1% - +0%
-9.82ms - +2.52ms
-unsure 🔍
-1% - +1%
-6.92ms - +4.51ms
previous-release
previous-release
804.51ms - 812.55msunsure 🔍
-1% - +0%
-8.59ms - +3.69ms
unsure 🔍
-1% - +1%
-4.51ms - +6.92ms
-

tachometer-reporter-action v2 for Benchmarks

// If `supportsAdoptingStyleSheets` is true then we assume CSSStyleSheet is
// constructable.
if (supportsAdoptingStyleSheets && this._styleSheet === undefined) {
(this._styleSheet = new CSSStyleSheet()).replaceSync(this.cssText);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is going to cause stylesheet duplication and css text re-parsing in some maybe still relatively common scenarios:

class BaseElement extends LitElement {
  static get styles() { return css`...`; }
}

class SubElementA extends BaseElement {
  static get styles() { return [BaseElement.styles, css`...`]; }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

It will however give a speedup on codebases that don't use a getter for styles, like all TS codebases, due to skipping a hash of a potentially long string.

I wonder if we can split the difference by caching based on the TemplateStringsArray, but only when the length is 1, so there are no interpolations to worry about.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR was based on #2978 and that change is made there, so let's discuss this change there?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh yeah... I paused that one to consider what to do about getters.

@sorvell
Copy link
Member Author

sorvell commented Sep 30, 2022

We've decided not to land this. See #3010 (comment).

@sorvell sorvell closed this Sep 30, 2022
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.

[reactive-element] Normalize adoptStyles so that it works x-browser when called to modify instance styles
2 participants