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

[lit-labs/observers] add base class #3386

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AndrewJakubowicz
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz commented Oct 21, 2022

Issue: #2350

This PR adds a base class to IntersectionController, ResizeController, and MutationController.

Fixed a bug where we accept a ResizeController config and then never use it. Fixed by passing the config to ResizeController.observe which was not previously done.

The rest of this change is only a refactor. Adding a new base class ObserverController.

To support adding the base class some properties needed their visibility changed from private to protected.

Size

With this PR:

File name Size Gzipped Brotli
resize_controller.js 509 B 298 B 247 B
mutation_controller.js 509 B 302 B 244 B
intersection_controller.js 590 B 328 B 268 B
observer_controller.js 534 B 309 B 262 B
Totals (including performance_controller) 3.03 kB 1.68 kB 1.37 kB

On main:

File name Size Gzipped Brotli
resize_controller.js 860 B 427 B 359 B
mutation_controller.js 860 B 436 B 365 B
intersection_controller.js 902 B 445 B 369 B
Totals (including performance_controller) 3.51 kB 1.76 kB 1.44 kB

Test plan

Tested by ensuring all tests continue passing unchanged.

Focus of this change was to tackle the simple cases and remove all
the duplicated logic.
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2022

🦋 Changeset detected

Latest commit: 3d70087

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

This PR includes changesets to release 1 package
Name Type
@lit-labs/observers Patch

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 Oct 21, 2022

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -4% - +6% (-1.23ms - +1.71ms)
    this-change vs tip-of-tree

render

  • lit-element-list: 110.19ms - 113.96ms
  • lit-html-kitchen-sink: unsure 🔍 -4% - +3% (-1.94ms - +1.52ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -5% - +5% (-0.75ms - +0.84ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -4% - +4% (-3.15ms - +3.11ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -1% - +3% (-0.85ms - +2.22ms)
    this-change vs tip-of-tree

update

  • lit-element-list: 1029.15ms - 1057.51ms
  • lit-html-kitchen-sink: unsure 🔍 -6% - +4% (-7.51ms - +5.60ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -4% - +2% (-16.44ms - +6.05ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -2% - +4% (-3.51ms - +6.71ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -4% - +2% (-40.40ms - +17.14ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: 1046.49ms - 1076.64ms
  • reactive-element-list: unsure 🔍 -3% - +1% (-37.39ms - +11.71ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs
110.19ms - 113.96ms-

update

VersionAvg timevs
1029.15ms - 1057.51ms-

update-reflect

VersionAvg timevs
1046.49ms - 1076.64ms-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
45.50ms - 47.96ms-unsure 🔍
-4% - +3%
-1.94ms - +1.52ms
unsure 🔍
-5% - +2%
-2.55ms - +1.17ms
tip-of-tree
tip-of-tree
45.73ms - 48.15msunsure 🔍
-3% - +4%
-1.52ms - +1.94ms
-unsure 🔍
-5% - +3%
-2.33ms - +1.37ms
previous-release
previous-release
46.03ms - 48.81msunsure 🔍
-3% - +5%
-1.17ms - +2.55ms
unsure 🔍
-3% - +5%
-1.37ms - +2.33ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
123.20ms - 131.78ms-unsure 🔍
-6% - +4%
-7.51ms - +5.60ms
unsure 🔍
-5% - +4%
-5.75ms - +5.42ms
tip-of-tree
tip-of-tree
123.49ms - 133.41msunsure 🔍
-4% - +6%
-5.60ms - +7.51ms
-unsure 🔍
-4% - +5%
-5.32ms - +6.90ms
previous-release
previous-release
124.09ms - 131.23msunsure 🔍
-4% - +5%
-5.42ms - +5.75ms
unsure 🔍
-5% - +4%
-6.90ms - +5.32ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
30.02ms - 31.76ms-unsure 🔍
-4% - +6%
-1.23ms - +1.71ms
unsure 🔍
-5% - +4%
-1.39ms - +1.34ms
tip-of-tree
tip-of-tree
29.47ms - 31.83msunsure 🔍
-6% - +4%
-1.71ms - +1.23ms
-unsure 🔍
-6% - +4%
-1.85ms - +1.31ms
previous-release
previous-release
29.86ms - 31.96msunsure 🔍
-4% - +5%
-1.34ms - +1.39ms
unsure 🔍
-4% - +6%
-1.31ms - +1.85ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
15.11ms - 15.91ms-unsure 🔍
-5% - +5%
-0.75ms - +0.84ms
unsure 🔍
-7% - +2%
-1.13ms - +0.37ms
tip-of-tree
tip-of-tree
14.78ms - 16.15msunsure 🔍
-5% - +5%
-0.84ms - +0.75ms
-unsure 🔍
-8% - +3%
-1.36ms - +0.50ms
previous-release
previous-release
15.26ms - 16.52msunsure 🔍
-2% - +7%
-0.37ms - +1.13ms
unsure 🔍
-3% - +9%
-0.50ms - +1.36ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
358.86ms - 373.36ms-unsure 🔍
-4% - +2%
-16.44ms - +6.05ms
unsure 🔍
-3% - +2%
-12.45ms - +8.64ms
tip-of-tree
tip-of-tree
362.71ms - 379.91msunsure 🔍
-2% - +5%
-6.05ms - +16.44ms
-unsure 🔍
-2% - +4%
-8.22ms - +14.80ms
previous-release
previous-release
360.36ms - 375.67msunsure 🔍
-2% - +3%
-8.64ms - +12.45ms
unsure 🔍
-4% - +2%
-14.80ms - +8.22ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
71.79ms - 76.32ms-unsure 🔍
-4% - +4%
-3.15ms - +3.11ms
unsure 🔍
-3% - +5%
-2.03ms - +3.94ms
tip-of-tree
tip-of-tree
71.92ms - 76.23msunsure 🔍
-4% - +4%
-3.11ms - +3.15ms
-unsure 🔍
-3% - +5%
-1.92ms - +3.88ms
previous-release
previous-release
71.15ms - 75.04msunsure 🔍
-5% - +3%
-3.94ms - +2.03ms
unsure 🔍
-5% - +3%
-3.88ms - +1.92ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
149.52ms - 157.45ms-unsure 🔍
-2% - +4%
-3.51ms - +6.71ms
unsure 🔍
-1% - +6%
-1.56ms - +8.89ms
tip-of-tree
tip-of-tree
148.66ms - 155.11msunsure 🔍
-4% - +2%
-6.71ms - +3.51ms
-unsure 🔍
-2% - +5%
-2.63ms - +6.75ms
previous-release
previous-release
146.42ms - 153.23msunsure 🔍
-6% - +1%
-8.89ms - +1.56ms
unsure 🔍
-4% - +2%
-6.75ms - +2.63ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
76.96ms - 79.26ms-unsure 🔍
-1% - +3%
-0.85ms - +2.22ms
unsure 🔍
-2% - +2%
-1.46ms - +1.78ms
tip-of-tree
tip-of-tree
76.41ms - 78.44msunsure 🔍
-3% - +1%
-2.22ms - +0.85ms
-unsure 🔍
-3% - +1%
-2.05ms - +1.00ms
previous-release
previous-release
76.81ms - 79.08msunsure 🔍
-2% - +2%
-1.78ms - +1.46ms
unsure 🔍
-1% - +3%
-1.00ms - +2.05ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1097.06ms - 1137.19ms-unsure 🔍
-4% - +2%
-40.40ms - +17.14ms
unsure 🔍
-4% - +1%
-41.34ms - +17.10ms
tip-of-tree
tip-of-tree
1108.14ms - 1149.38msunsure 🔍
-2% - +4%
-17.14ms - +40.40ms
-unsure 🔍
-3% - +3%
-30.09ms - +29.11ms
previous-release
previous-release
1108.00ms - 1150.49msunsure 🔍
-2% - +4%
-17.10ms - +41.34ms
unsure 🔍
-3% - +3%
-29.11ms - +30.09ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1135.36ms - 1169.16ms-unsure 🔍
-3% - +1%
-37.39ms - +11.71ms
unsure 🔍
-3% - +1%
-35.82ms - +15.38ms
tip-of-tree
tip-of-tree
1147.30ms - 1182.90msunsure 🔍
-1% - +3%
-11.71ms - +37.39ms
-unsure 🔍
-2% - +2%
-23.58ms - +28.83ms
previous-release
previous-release
1143.25ms - 1181.70msunsure 🔍
-1% - +3%
-15.38ms - +35.82ms
unsure 🔍
-2% - +2%
-28.83ms - +23.58ms
-

tachometer-reporter-action v2 for Benchmarks

import {
ObserverController,
type ObserverControllerConfig,
} from './observer_controller.js';

Choose a reason for hiding this comment

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

nit: I noticed a lot of other lit packages use kebab case instead of snake case for file naming. Is it worth changing the names of these controllers to normalize consumption with the remainder of the lit repo?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just did this here: #3771

@shaal
Copy link

shaal commented Mar 29, 2023

Lit's ResizeController always call render() twice, before any size changes.
Simplified example - https://lit.dev/playground/#gist=d26a19ef6637e12160c703079e37c9af

When using {skipInitial = true}, does this PR solve that problem?

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.

5 participants