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

Skip to content

Conversation

@sorvell
Copy link
Member

@sorvell sorvell commented Dec 5, 2021

Fixes #2323 and #2317.

  • Tasks automatically run whenever their arguments change. A task with no arguments does not run; a task with an empty array of arguments runs once; otherwise tasks runs when its arguments array members differs from is previous arguments.
  • The automatic running of tasks based on arguments can be disabled by setting autoRun to false. This can be done via the task config or by setting the property on the task itself.
  • Call run() (optionally specifying task arguments) to explicitly run the task.

Steven Orvell added 2 commits December 5, 2021 10:59
Fixes #2323 and #2317.
* Tasks with no arguments now run by default if they are not pending and not signaling a status change.
* Can specify a `canRun` method . It receives arguments of a default `canRun()` function, the task's status, and the values of the task's arguments.
* Adds option to specify task arguments via a config object and this is how canRun is used {task, arguments?, canRun?}
* Changes Task "dependencies" to "arguments."
@sorvell sorvell requested a review from justinfagnani December 5, 2021 19:02
@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2021

🦋 Changeset detected

Latest commit: 298f31a

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

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

@google-cla google-cla bot added the cla: yes label Dec 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2021

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -7% - +2% (-2.37ms - +0.70ms)
    this-change vs tip-of-tree

render

  • lit-element-list: unsure 🔍 -4% - +6% (-3.82ms - +6.34ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -2% - +9% (-0.83ms - +3.41ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -12% - +1% (-1.91ms - +0.21ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: slower ❌ 0% - 6% (0.06ms - 4.25ms)
    this-change vs tip-of-tree
  • reactive-element-list: slower ❌ 1% - 11% (0.73ms - 7.31ms)
    this-change vs tip-of-tree

update

  • lit-element-list: unsure 🔍 -3% - +1% (-33.42ms - +10.35ms)
    this-change vs tip-of-tree
  • lit-html-kitchen-sink: unsure 🔍 -8% - +4% (-8.56ms - +4.27ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -3% - +2% (-13.19ms - +6.05ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -1% - +5% (-1.26ms - +7.53ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -2% - +2% (-19.77ms - +18.38ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: unsure 🔍 -4% - +1% (-41.75ms - +8.36ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -3% - +1% (-36.55ms - +7.07ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
99.93ms - 107.45ms-unsure 🔍
-4% - +6%
-3.82ms - +6.34ms
faster ✔
16% - 24%
19.64ms - 31.19ms
tip-of-tree
tip-of-tree
99.01ms - 105.85msunsure 🔍
-6% - +4%
-6.34ms - +3.82ms
-faster ✔
17% - 24%
21.12ms - 32.24ms
previous-release
previous-release
124.72ms - 133.49msslower ❌
18% - 31%
19.64ms - 31.19ms
slower ❌
20% - 32%
21.12ms - 32.24ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
944.04ms - 974.38ms-unsure 🔍
-3% - +1%
-33.42ms - +10.35ms
faster ✔
7% - 11%
71.24ms - 115.82ms
tip-of-tree
tip-of-tree
954.98ms - 986.52msunsure 🔍
-1% - +3%
-10.35ms - +33.42ms
-faster ✔
6% - 10%
59.30ms - 104.70ms
previous-release
previous-release
1036.42ms - 1069.07msslower ❌
7% - 12%
71.24ms - 115.82ms
slower ❌
6% - 11%
59.30ms - 104.70ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1045.78ms - 1085.23ms-unsure 🔍
-4% - +1%
-41.75ms - +8.36ms
faster ✔
2% - 7%
22.11ms - 75.90ms
tip-of-tree
tip-of-tree
1066.74ms - 1097.66msunsure 🔍
-1% - +4%
-8.36ms - +41.75ms
-faster ✔
1% - 5%
8.37ms - 56.26ms
previous-release
previous-release
1096.23ms - 1132.80msslower ❌
2% - 7%
22.11ms - 75.90ms
slower ❌
1% - 5%
8.37ms - 56.26ms
-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
38.83ms - 42.08ms-unsure 🔍
-2% - +9%
-0.83ms - +3.41ms
faster ✔
11% - 20%
5.24ms - 9.78ms
tip-of-tree
tip-of-tree
37.81ms - 40.53msunsure 🔍
-8% - +2%
-3.41ms - +0.83ms
-faster ✔
14% - 22%
6.70ms - 10.89ms
previous-release
previous-release
46.37ms - 49.56msslower ❌
12% - 25%
5.24ms - 9.78ms
slower ❌
17% - 28%
6.70ms - 10.89ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
105.52ms - 113.83ms-unsure 🔍
-8% - +4%
-8.56ms - +4.27ms
unsure 🔍
-8% - +3%
-9.03ms - +3.15ms
tip-of-tree
tip-of-tree
106.93ms - 116.71msunsure 🔍
-4% - +8%
-4.27ms - +8.56ms
-unsure 🔍
-7% - +5%
-7.40ms - +5.82ms
previous-release
previous-release
108.16ms - 117.07msunsure 🔍
-3% - +8%
-3.15ms - +9.03ms
unsure 🔍
-5% - +7%
-5.82ms - +7.40ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
31.41ms - 33.36ms-unsure 🔍
-7% - +2%
-2.37ms - +0.70ms
faster ✔
15% - 22%
5.90ms - 8.94ms
tip-of-tree
tip-of-tree
32.03ms - 34.41msunsure 🔍
-2% - +7%
-0.70ms - +2.37ms
-faster ✔
13% - 20%
4.92ms - 8.25ms
previous-release
previous-release
38.63ms - 40.98msslower ❌
18% - 28%
5.90ms - 8.94ms
slower ❌
14% - 25%
4.92ms - 8.25ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
14.18ms - 15.30ms-unsure 🔍
-12% - +1%
-1.91ms - +0.21ms
faster ✔
2% - 16%
0.28ms - 2.70ms
tip-of-tree
tip-of-tree
14.68ms - 16.49msunsure 🔍
-2% - +13%
-0.21ms - +1.91ms
-unsure 🔍
-12% - +4%
-2.04ms - +0.76ms
previous-release
previous-release
15.15ms - 17.30msslower ❌
2% - 19%
0.28ms - 2.70ms
unsure 🔍
-5% - +13%
-0.76ms - +2.04ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
382.96ms - 396.84ms-unsure 🔍
-3% - +2%
-13.19ms - +6.05ms
faster ✔
30% - 33%
164.89ms - 190.43ms
tip-of-tree
tip-of-tree
386.80ms - 400.13msunsure 🔍
-2% - +3%
-6.05ms - +13.19ms
-faster ✔
29% - 32%
161.47ms - 186.72ms
previous-release
previous-release
556.84ms - 578.28msslower ❌
42% - 49%
164.89ms - 190.43ms
slower ❌
41% - 48%
161.47ms - 186.72ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
69.47ms - 72.67ms-slower ❌
0% - 6%
0.06ms - 4.25ms
faster ✔
14% - 19%
11.55ms - 16.33ms
tip-of-tree
tip-of-tree
67.57ms - 70.27msfaster ✔
0% - 6%
0.06ms - 4.25ms
-faster ✔
17% - 21%
13.87ms - 18.32ms
previous-release
previous-release
83.24ms - 86.78msslower ❌
16% - 23%
11.55ms - 16.33ms
slower ❌
20% - 27%
13.87ms - 18.32ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
147.35ms - 153.91ms-unsure 🔍
-1% - +5%
-1.26ms - +7.53ms
faster ✔
11% - 16%
18.07ms - 27.96ms
tip-of-tree
tip-of-tree
144.57ms - 150.42msunsure 🔍
-5% - +1%
-7.53ms - +1.26ms
-faster ✔
13% - 18%
21.43ms - 30.87ms
previous-release
previous-release
169.94ms - 177.35msslower ❌
12% - 19%
18.07ms - 27.96ms
slower ❌
14% - 21%
21.43ms - 30.87ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
71.20ms - 75.83ms-slower ❌
1% - 11%
0.73ms - 7.31ms
unsure 🔍
-2% - +8%
-1.41ms - +5.69ms
tip-of-tree
tip-of-tree
67.16ms - 71.83msfaster ✔
1% - 10%
0.73ms - 7.31ms
-unsure 🔍
-8% - +2%
-5.44ms - +1.68ms
previous-release
previous-release
68.69ms - 74.07msunsure 🔍
-8% - +2%
-5.69ms - +1.41ms
unsure 🔍
-2% - +8%
-1.68ms - +5.44ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
957.39ms - 984.41ms-unsure 🔍
-2% - +2%
-19.77ms - +18.38ms
unsure 🔍
-2% - +2%
-19.57ms - +20.99ms
tip-of-tree
tip-of-tree
958.13ms - 985.06msunsure 🔍
-2% - +2%
-18.38ms - +19.77ms
-unsure 🔍
-2% - +2%
-18.84ms - +21.65ms
previous-release
previous-release
955.07ms - 985.31msunsure 🔍
-2% - +2%
-20.99ms - +19.57ms
unsure 🔍
-2% - +2%
-21.65ms - +18.84ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1079.89ms - 1111.95ms-unsure 🔍
-3% - +1%
-36.55ms - +7.07ms
unsure 🔍
-4% - +0%
-42.82ms - +2.62ms
tip-of-tree
tip-of-tree
1095.87ms - 1125.46msunsure 🔍
-1% - +3%
-7.07ms - +36.55ms
-unsure 🔍
-2% - +1%
-27.23ms - +16.51ms
previous-release
previous-release
1099.92ms - 1132.13msunsure 🔍
-0% - +4%
-2.62ms - +42.82ms
unsure 🔍
-1% - +2%
-16.51ms - +27.23ms
-

tachometer-reporter-action v2 for Benchmarks

@justinfagnani
Copy link
Collaborator

justinfagnani commented Dec 6, 2021

I still like the idea that a Task with no args function is no auto-run at all, and a task with an empty args array is auto-run because there's no args to dirty-check:

new Task(host, fn); // not auto-run
new Task(host, fn, () => []); // auto-run

canRun is still a good feature, but I'm not sure a default of running every host update is what users would expect from not providing an args function, and it looks like it's very involved to make a manually run task because canRun needs to vary returning true or false since it's checked even in the manual call to runTask(). So I think we'd still need a simple way to make a manually-run Task.

Is this how we'd have to do it with canRun now?

class MyElement extends LitElement {
  private _task = new Task(this, {task: async() => {...}, canRun: () => this._canRunTask});
  private @state _canRunTask = false;
  private async _runTask() {
    this._canRunTask = true;
    this._task.runTask();
    await this._task.taskComplete;
    this._canRunTask = false;
  }
  
  private _onRunButtonClick() {
    this._runTask();
  }
}

I'd like to see something more like:

class MyElement extends LitElement {
  private _task = new Task(this, async() => {...});
  
  private _onRunButtonClick() {
    this._task.run();
  }
}

@sorvell
Copy link
Member Author

sorvell commented Dec 6, 2021

Thinking about this again, I think probably canRun should be removed because it's a bit cumbersome as you pointed out. I think instead:

  • when args are specified, the Task will always run at least once and then if/when the args change.
  • when no args function is specified, the Task will be in manual mode
  • a autoRun will be added which can be set to false but defaults to true (and is settable on the task task.autoRun = false
  • expose run() to manually run.
  • maybe eliminate canRun and if not call is shouldRun.

@justinfagnani justinfagnani changed the title [labs\task] Runs tasks without arguments by default and adds canRun for customization. [@lit-labs/task] Runs tasks without arguments by default and adds canRun for customization. Dec 7, 2021
@justinfagnani justinfagnani added this to the Lit 2.1 milestone Dec 7, 2021
Steven Orvell added 2 commits December 6, 2021 19:57
* tasks run whenever args change
* disable this by setting `autoRun` to false, either in the task config or later on the task
* call `run(args?)` explicitly to force the task to run
@sorvell sorvell changed the title [@lit-labs/task] Runs tasks without arguments by default and adds canRun for customization. [@lit-labs/task] Refines when tasks are run Dec 7, 2021
@sorvell sorvell requested a review from justinfagnani December 7, 2021 04:02
this._task = task;
this._getDependencies = getDependencies;
this._getArgs = args;
this.taskComplete = new Promise((res, rej) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this change for manual run tasks so that it's a resolved promise?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you explain why?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering what await task.taskComplete should do for a manually run task? The task is idle, but it's not necessarily ever going to run. In some ways it seems like a task that has completed some times, and might or might not run again, and in that case taskComplete would be a resolved promise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's handle this as a follow on. Filed #2347.

@sorvell sorvell requested a review from justinfagnani December 7, 2021 13:17
@sorvell sorvell requested a review from justinfagnani December 8, 2021 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[@lit-labs/task] Tasks that don't start immediately

2 participants