Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@justinfagnani
Copy link
Collaborator

@justinfagnani justinfagnani commented Jul 8, 2023

Fixes #4003
Fixes #1808 (there were some issues in the jsdoc example)

This is a breaking change.

This also adds 'afterUpdate' as a valid value for autoRun, which preserves the existing timing. That's useful for tasks that need to read state changes in update, such as DOM.

@changeset-bot
Copy link

changeset-bot bot commented Jul 8, 2023

🦋 Changeset detected

Latest commit: b359737

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/task Major

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 Jul 8, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -14% - +3% (-3.27ms - +0.73ms)
    this-change vs tip-of-tree

render

  • lit-element-list: 71.81ms - 75.05ms
  • lit-html-kitchen-sink: unsure 🔍 -13% - +1% (-4.40ms - +0.35ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -2% - +6% (-0.15ms - +0.64ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -1% - +4% (-0.34ms - +2.06ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +3% (-0.89ms - +1.21ms)
    this-change vs tip-of-tree

update

  • lit-element-list: 869.82ms - 880.48ms
  • lit-html-kitchen-sink: unsure 🔍 -1% - +10% (-0.73ms - +7.57ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -9% - +11% (-30.50ms - +36.04ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -3% - +0% (-4.34ms - +0.24ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +0% (-17.55ms - +2.33ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: 820.87ms - 830.75ms
  • reactive-element-list: unsure 🔍 -1% - +1% (-4.66ms - +12.84ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs
71.81ms - 75.05ms-

update

VersionAvg timevs
869.82ms - 880.48ms-

update-reflect

VersionAvg timevs
820.87ms - 830.75ms-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
28.36ms - 31.48ms-unsure 🔍
-13% - +1%
-4.40ms - +0.35ms
unsure 🔍
-14% - -0%
-4.51ms - +0.06ms
tip-of-tree
tip-of-tree
30.16ms - 33.73msunsure 🔍
-1% - +15%
-0.35ms - +4.40ms
-unsure 🔍
-8% - +7%
-2.64ms - +2.24ms
previous-release
previous-release
30.48ms - 33.81msunsure 🔍
-0% - +15%
-0.06ms - +4.51ms
unsure 🔍
-7% - +8%
-2.24ms - +2.64ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
80.43ms - 85.94ms-unsure 🔍
-1% - +10%
-0.73ms - +7.57ms
unsure 🔍
-5% - +5%
-4.58ms - +4.06ms
tip-of-tree
tip-of-tree
76.66ms - 82.87msunsure 🔍
-9% - +1%
-7.57ms - +0.73ms
-unsure 🔍
-10% - +1%
-8.23ms - +0.87ms
previous-release
previous-release
80.12ms - 86.76msunsure 🔍
-5% - +6%
-4.06ms - +4.58ms
unsure 🔍
-1% - +10%
-0.87ms - +8.23ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
20.77ms - 22.94ms-unsure 🔍
-14% - +3%
-3.27ms - +0.73ms
unsure 🔍
-13% - +2%
-2.98ms - +0.62ms
tip-of-tree
tip-of-tree
21.44ms - 24.80msunsure 🔍
-3% - +15%
-0.73ms - +3.27ms
-unsure 🔍
-9% - +10%
-2.12ms - +2.30ms
previous-release
previous-release
21.59ms - 24.47msunsure 🔍
-3% - +14%
-0.62ms - +2.98ms
unsure 🔍
-10% - +9%
-2.30ms - +2.12ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
9.97ms - 10.60ms-unsure 🔍
-2% - +6%
-0.15ms - +0.64ms
unsure 🔍
-4% - +3%
-0.42ms - +0.36ms
tip-of-tree
tip-of-tree
9.80ms - 10.28msunsure 🔍
-6% - +1%
-0.64ms - +0.15ms
-unsure 🔍
-6% - +0%
-0.61ms - +0.05ms
previous-release
previous-release
10.09ms - 10.55msunsure 🔍
-3% - +4%
-0.36ms - +0.42ms
unsure 🔍
-1% - +6%
-0.05ms - +0.61ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
310.20ms - 360.37ms-unsure 🔍
-9% - +11%
-30.50ms - +36.04ms
unsure 🔍
-8% - +13%
-26.47ms - +42.53ms
tip-of-tree
tip-of-tree
310.65ms - 354.37msunsure 🔍
-11% - +9%
-36.04ms - +30.50ms
-unsure 🔍
-8% - +12%
-26.97ms - +37.49ms
previous-release
previous-release
303.56ms - 350.94msunsure 🔍
-13% - +8%
-42.53ms - +26.47ms
unsure 🔍
-11% - +8%
-37.49ms - +26.97ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
52.81ms - 54.66ms-unsure 🔍
-1% - +4%
-0.34ms - +2.06ms
unsure 🔍
-1% - +4%
-0.66ms - +1.99ms
tip-of-tree
tip-of-tree
52.11ms - 53.64msunsure 🔍
-4% - +1%
-2.06ms - +0.34ms
-unsure 🔍
-3% - +2%
-1.42ms - +1.02ms
previous-release
previous-release
52.12ms - 54.02msunsure 🔍
-4% - +1%
-1.99ms - +0.66ms
unsure 🔍
-2% - +3%
-1.02ms - +1.42ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
123.36ms - 126.29ms-unsure 🔍
-3% - +0%
-4.34ms - +0.24ms
unsure 🔍
-2% - +2%
-2.12ms - +2.46ms
tip-of-tree
tip-of-tree
125.12ms - 128.63msunsure 🔍
-0% - +3%
-0.24ms - +4.34ms
-unsure 🔍
-0% - +4%
-0.27ms - +4.70ms
previous-release
previous-release
122.90ms - 126.42msunsure 🔍
-2% - +2%
-2.46ms - +2.12ms
unsure 🔍
-4% - +0%
-4.70ms - +0.27ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
47.04ms - 48.54ms-unsure 🔍
-2% - +3%
-0.89ms - +1.21ms
unsure 🔍
-3% - +2%
-1.22ms - +0.82ms
tip-of-tree
tip-of-tree
46.90ms - 48.36msunsure 🔍
-3% - +2%
-1.21ms - +0.89ms
-unsure 🔍
-3% - +1%
-1.36ms - +0.65ms
previous-release
previous-release
47.30ms - 48.67msunsure 🔍
-2% - +3%
-0.82ms - +1.22ms
unsure 🔍
-1% - +3%
-0.65ms - +1.36ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
914.39ms - 927.24ms-unsure 🔍
-2% - +0%
-17.55ms - +2.33ms
unsure 🔍
-1% - +1%
-11.49ms - +6.68ms
tip-of-tree
tip-of-tree
920.84ms - 936.01msunsure 🔍
-0% - +2%
-2.33ms - +17.55ms
-unsure 🔍
-1% - +2%
-4.73ms - +15.14ms
previous-release
previous-release
916.80ms - 929.64msunsure 🔍
-1% - +1%
-6.68ms - +11.49ms
unsure 🔍
-2% - +1%
-15.14ms - +4.73ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
890.88ms - 902.98ms-unsure 🔍
-1% - +1%
-4.66ms - +12.84ms
unsure 🔍
-1% - +1%
-5.14ms - +10.74ms
tip-of-tree
tip-of-tree
886.51ms - 899.16msunsure 🔍
-1% - +1%
-12.84ms - +4.66ms
-unsure 🔍
-1% - +1%
-9.44ms - +6.86ms
previous-release
previous-release
888.98ms - 899.27msunsure 🔍
-1% - +1%
-10.74ms - +5.14ms
unsure 🔍
-1% - +1%
-6.86ms - +9.44ms
-

tachometer-reporter-action v2 for Benchmarks

@justinfagnani justinfagnani changed the title Run tasks in update instead of updated ]labs/task] Run tasks in update instead of updated Jul 8, 2023
@justinfagnani justinfagnani changed the title ]labs/task] Run tasks in update instead of updated [labs/task] Run tasks in update instead of updated Jul 8, 2023
@e111077
Copy link
Contributor

e111077 commented Jul 8, 2023

This is a difficult choice. Updated we can be pretty sure all computed properties should be synced by then. Also we know DOM will always be ready in the task. Can you spin up an example real quick with a task that accesses a @query and see how it looks DX-wise?

An example can maybe be a list of items with a [selected] attribute or something like select and option but you don't hook the value into the Lit data system

@justinfagnani
Copy link
Collaborator Author

@e111077 yeah, I can add that as a test. A task will not be able to see rendered updates though. I think we need to find a case where something doesn't work at all, not just that we get a double-render, and let that guide us. If someone wanted to trigger a task based on updated shadow root contents... is that a supported case?

I thought we kind of resolved to do this a while back, based on this comment: #1499 (comment)

But... do we need this to be configurable? runAfterUpdate: true?

@e111077
Copy link
Contributor

e111077 commented Jul 8, 2023

Personally don't care about a test case too much just want to investigate the DX. Like does the queried property go in the arguments list now? It won't trigger a re-render when it updates but it will trigger dirty props etc.

@justinfagnani
Copy link
Collaborator Author

I mean to add the test case as a reviewed, checked-in, working example of the DX, with some assertions about whether it works. I don't think this will be a good case with the new timing, so I want to get it in and have eyes on it.

@justinfagnani
Copy link
Collaborator Author

I added the test/example (didn't push yet) and... I don't know. It might be better to take the double-render hit on pending tasks.

For many cases, and especially SSR compatibility, update timing is better. So I wonder if we should have an option, and what the default should be? Is depending on DOM common? Could tasks using updated timing skip SSR?

@e111077
Copy link
Contributor

e111077 commented Jul 8, 2023

If we keep it as so we push people towards the data system rather than accessing DOM directly which is arguably "idiomatic Lit".

So someone in updated or firstUpdated can access the DOM, update a reactive property dependency in the Task props array, and then the rerender on update can catch it. The Task may run twice (perhaps noop the first time) but the element in both cases would lifecycle twice. But in the cases where state doesn't rely on DOM (a fully SSR-able component) then there is no double render.

Idk drawbacks either way, but I'd argue the DOM case is not as common but not uncommon

@justinfagnani
Copy link
Collaborator Author

What about:

  autoRun?: boolean | 'afterUpdate'

The default timing would be hostUpdate and afterUpdate would revert to the current timing. afterUpdate probably wouldn't be SSR compatible.

@justinfagnani
Copy link
Collaborator Author

@e111077 I added a autoRun: 'afterUpdate' option, and I think it might be a good solution. I pushed the change and tests that show it working with DOM.

(I can't for the life of me figure out why the task tests can't see the lit package though)

@e111077
Copy link
Contributor

e111077 commented Jul 9, 2023

Also wondering why not willUpdate? That would allow fetches to be completed on the server and send pure HTML to the user... Oh I guess reactive controllers don't have hostWillUpdate.

I think letting the user select the lifecycle like this is a decent idea. Would be cool if we could enable server fetches though

@justinfagnani
Copy link
Collaborator Author

Yeah, we don't have hostWillUpdate() and if we did it would go before willUpdate() as the other callbacks do, which I don't think would be very useful.

I think we can enable server fetches - easier - with the new default timing. @kevinpschaaf had a branch that made SSR wait for async controllers, and this timing lets us know sooner that a task will have been started.

Copy link
Contributor

@e111077 e111077 left a comment

Choose a reason for hiding this comment

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

LGTM pending Peter's suggestions, though I reckon the migration for users is not gonna be great. Personally not looking forward to upgrading my implementations

@justinfagnani justinfagnani requested a review from rictic July 11, 2023 00:17
@justinfagnani justinfagnani merged commit 5beb5f9 into main Jul 11, 2023
@justinfagnani justinfagnani deleted the task-timing branch July 11, 2023 04:36
@lit-robot lit-robot mentioned this pull request Aug 2, 2023
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.

[labs/task] Tasks should run in hostUpdate(), not hostUpdate() [labs/task] Improve README.md usage example

3 participants