Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@iskakaushik
Copy link
Contributor

@iskakaushik iskakaushik commented Mar 30, 2021

Task Source

Introduces a notion of a TaskSource. TaskSource provides the task dispatcher (MessageLoopTaskQueues) an abstraction to obtain the next task to run. TaskSources as implemented in the PR have two managed task heaps. kPrimary and kSecondary task heaps. When registering a task with the task dispatcher, we provide a way to specify whether the task is for the kPrimiary or kSecondary task heap. Secondary heaps can be paused and resumed.

Usage

  1. During a frame workload, on vsync, we pause the secondary heap on the UI thread's task source. This is later resumed on the completion of the frame build process.
  2. As a part of this change, all the HandleMessage calls on a dart isolate are also serviced by the secondary heap of the UI thread's task source.

This makes it so that all non-frame build related events on the UI threads are paused on vsync and we re enable them only when the frame gets built. See: go/flutter-engine-task-prioritization.

Benchmarks

animation_with_microtasks_perf

lands the framework to address: flutter/flutter#69694

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@iskakaushik
Copy link
Contributor Author

@chinmaygarde this PR is mostly ready, I still need to write tests for this, wanted to get your take on this before I go ahead with it.

@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Apr 1, 2021
@iskakaushik iskakaushik force-pushed the event_loop_scheduling branch from c74d60b to 934a678 Compare April 12, 2021 16:58
@iskakaushik iskakaushik changed the title [WIP] Improve the scheduling of events on the UI thread Improve the scheduling of events on the UI thread Apr 12, 2021
@flutter-dashboard flutter-dashboard bot added the embedder Related to the embedder API label Apr 12, 2021
@iskakaushik iskakaushik removed the Work in progress (WIP) Not ready (yet) for review! label Apr 12, 2021
@iskakaushik iskakaushik force-pushed the event_loop_scheduling branch from 237f4a9 to 6e07478 Compare April 12, 2021 17:50
Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

This is extremely compelling stuff. I did an initial pass over the interface with some suggestions for your consideration. Looking at the implementation in detail now. Thanks!


void Clear();

void RegisterTask(TaskSourceGrade grade, DelayedTask&& task);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can DelayedTask have its copy ctor disabled? We can then remove the && and ensure that it is impossible to have unnecessary copies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing this, looks like using a priority queue without a copy constructor is non-trivial. Will attempt doing this in a future PR.

Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

This is so awesome.

switch (task.GetTaskSourceGrade()) {
case TaskSourceGrade::kUserInteraction:
primary_task_queue_.push(task);
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Here and later, you can use [[fallthrough]] if the compiler troubles you about the missing break. You call though.

1. Add tests for TaskSource
2. Add docs for TaskSource
3. Get existing failing tests to pass
@iskakaushik iskakaushik force-pushed the event_loop_scheduling branch from 2dd11ca to f49ec77 Compare April 16, 2021 16:43
@iskakaushik iskakaushik force-pushed the event_loop_scheduling branch from f49ec77 to 7795d8d Compare April 16, 2021 18:41
@iskakaushik
Copy link
Contributor Author

@chinmaygarde I've noticed a couple of assumptions in the profiler initialization code that prevents us from pausing the micro task queue on vsync start. We have to do it after the first frame renders. I'm landing the changes to the task management as done in this PR. I will address these issues (in a much smaller patch) in a follow-up PR.

@iskakaushik iskakaushik changed the title Improve the scheduling of events on the UI thread TaskSources register tasks with MessageLoopTaskQueues dispatcher Apr 19, 2021
@iskakaushik iskakaushik merged commit f2f09b6 into flutter:master Apr 19, 2021
@iskakaushik iskakaushik deleted the event_loop_scheduling branch April 19, 2021 14:20
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 19, 2021
@chinmaygarde
Copy link
Contributor

I'm landing the changes to the task management as done in this PR.

SGTM.

iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 20, 2021
This is because tests don't really wait for vsync to complete

Fixes: flutter/flutter#69694

See: flutter#25307 (comment)
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 20, 2021
This is because tests don't really wait for vsync to complete

Fixes: flutter/flutter#69694

See: flutter#25307 (comment)
@zanderso
Copy link
Member

Does this also close flutter/flutter#69694?

iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 20, 2021
This is because tests don't really wait for vsync to complete

Fixes: flutter/flutter#69694

See: flutter#25307 (comment)
@iskakaushik
Copy link
Contributor Author

iskakaushik commented Apr 20, 2021

@zanderso not yet, this lands the framework to prioritize tasks. I did not prioritize the tasks just yet. That's WIP at #25653.

iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 20, 2021
This is because tests don't really wait for vsync to complete

Fixes: flutter/flutter#69694

See: flutter#25307 (comment)
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 20, 2021
This is because tests don't really wait for vsync to complete

Fixes: flutter/flutter#69694

See: flutter#25307 (comment)
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 20, 2021
This is because tests don't really wait for vsync to complete

Fixes: flutter/flutter#69694

See: flutter#25307 (comment)
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 21, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 21, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Apr 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes embedder Related to the embedder API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants