Commit Graph

17 Commits

Author SHA1 Message Date
Samuel Susla dbda1917cc Make RuntimeScheduler module compile in C++ 14
Summary:
changelog: [internal]

Don't use C++ 17 features in RuntimeScheduler module as it needs to be imported into C++14 module.

Also removes redundant dependency.

Reviewed By: ShikaSD

Differential Revision: D30485642

fbshipit-source-id: 0a20f85c596eebe193affc815c8ca851fc72e46d
2021-09-01 11:26:27 -07:00
Samuel Susla 74608417df Before removing a task from queue, make sure it was executed
Summary:
Changelog: [internal]

If task that is being executed schedules a new task with higher priority, the new task will be dropped from the queue. To fix this, we always check if the top of the queue is what was executed and only then remove it.

Example:
Let's say there is task A with priority "normal".

When we execute task A (which is not removed from the queue until later), it adds a task B with "immediate" priority.
So priority queue now has two tasks: [1: B, 2: A]

After task A finishes, inside workLoop, it will pop from top of the priority queue. But task A is no longer top of the priority queue (this is the bug) and it pops B. B is never executed and A is executed twice.

Reviewed By: ShikaSD

Differential Revision: D29841433

fbshipit-source-id: b2f1474fdfc7b3e2d42bae5b7f4ac7e6c3a37b54
2021-07-25 15:39:00 -07:00
Samuel Susla e24b55ef4f Clean up RuntimeScheduler's API
Summary:
Changelog: [internal]

Mark methods as noexcept and explicitly delete unwanted constructors.

Reviewed By: fkgozali

Differential Revision: D29085827

fbshipit-source-id: 872009113e2bd519ab3ae11879a15d15f780198f
2021-06-13 07:55:29 -07:00
Samuel Susla 3a9e14e8a9 Add synchronous access to the runtime to RuntimeScheduler
Summary:
Changelog: [internal]

Introduces synchronous access to the runtime from RuntimeScheduler.
At the moment, this is not used anywhere.

In case RuntimeScheduler isn't defined (controlled by MC), falls back to RuntimeExecutor.

Reviewed By: mdvacca

Differential Revision: D28024380

fbshipit-source-id: 90be36dd390202540ed51940a4396040f043cd90
2021-05-25 07:42:06 -07:00
Samuel Susla ca499a6197 Group public and private methods in RuntimeScheduler
Summary:
Changelog: [internal]

Only moves methods around so public and private methods are grouped together.

Reviewed By: JoshuaGross

Differential Revision: D28381588

fbshipit-source-id: dae7f493b99845f66070689270bc7aef958fbecd
2021-05-13 08:03:29 -07:00
Samuel Susla 52a995d611 Add yielding mechanism to RuntimeScheduler
Summary:
Changelog: [internal]

Add yielding mechanism to RuntimeScheduler. It is disabled unless `RuntimeScheduler::setEnableYielding` is called.

Reviewed By: JoshuaGross

Differential Revision: D28024376

fbshipit-source-id: 12a7d09d201962e10cadcb352df4967657345d36
2021-05-13 08:03:29 -07:00
Samuel Susla 9b3c12dc87 Funnel All Fabric calls to RuntimeExecutor to RuntimeScheduler
Summary:
Changelog: [internal]

This diff moves all calls to RuntimeExecutor to RuntimeScheduler. The calls are still immediately dispatched. Timing of events will not change.

The goal of this diff is to prepare infrastructure for Concurrent Mode.

Reviewed By: JoshuaGross

Differential Revision: D27937665

fbshipit-source-id: 434d78c95ccf23d8da41186d0dae91bff4eda384
2021-05-13 08:03:29 -07:00
Samuel Susla 841756b150 Implement RuntimeScheduler::getCurrentPriorityLevel
Summary:
Changelog: [internal]

Implement `RuntimeScheduler::getCurrentPriorityLevel`.

JavaScript implementation: https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L63

Reviewed By: ShikaSD

Differential Revision: D27998510

fbshipit-source-id: 634c09185f9eae8f7afcdb6acd9b74effd587da7
2021-04-27 00:29:04 -07:00
Samuel Susla a8d0dd6646 Implement task continuation
Summary:
Changelog: [internal]

Scheduler's callback have option to add more work inside callback. This work stays on top of the priority queue and gives React ability to flush all work synchronously if need.

This diff adds use of `shouldYield_` to the workLoop. For now, it always evaluates to false. In the future when we allow access to the scheduler to native, it will allow yielding.

Relevant code in JavaScript:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L190

Reviewed By: mdvacca

Differential Revision: D27823528

fbshipit-source-id: 016101e41eb7c41c2ac5abb55f803814867b8517
2021-04-20 09:22:23 -07:00
Samuel Susla 318e9f283e Execute multiple tasks within single dispatch
Summary:
Changelog: [internal]

This brings native scheduler close to React's scheduler. React's scheduler executes all tasks in the queue within a single dispatch (they use setTimeout(0) for dispatch) and makes sure to not schedule two dispatches.

Relevant JS code:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L359

Reviewed By: JoshuaGross

Differential Revision: D27793200

fbshipit-source-id: 4af13d95cfe4d33d0945f25929ccbea5f9ce5710
2021-04-16 08:16:41 -07:00
Samuel Susla e3a4de8b55 Add unit tests for RuntimeScheduler::now
Summary:
changelog: [internal]

Add unit tests for `RuntimeScheduler::now`

Reviewed By: JoshuaGross

Differential Revision: D27763852

fbshipit-source-id: 1edec8e8338e9d9798b95c55d07114be05f555b8
2021-04-15 02:44:13 -07:00
Samuel Susla 06753d431a Add expiration date to Task and use it to determine priority
Summary:
Changelog: [internal]

To prevent starvation, this diff implements expiration time as a way to order tasks in priority queue. This stops higher priority tasks from preventing lower priority tasks from running. The same mechanism is implemented in [JavaScript's scheduler](https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js).

Reviewed By: mdvacca

Differential Revision: D27707887

fbshipit-source-id: 3dc734c856a166ef5c17c5045ebd429565ba79f0
2021-04-14 02:53:24 -07:00
Samuel Susla 240588b6d4 Implement RuntimeScheduler::now
Summary:
Changelog: [internal]

Implement RuntimeScheduler::now and exposite it to JavaScript. JavaScripts expects miliseconds and is using `performance.now()` call to get this value.

More about `performance.now()`: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
JavaScript implementation in Scheduler: https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L71-L82

Reviewed By: JoshuaGross

Differential Revision: D27675512

fbshipit-source-id: bce5ac700e71b1722cd280dfbdd15e141783a3a5
2021-04-14 02:53:24 -07:00
Samuel Susla cc3e87c45b Implement RuntimeScheduler::getShouldYield
Summary:
Changelog: [internal]

Implement RuntimeScheduler::getShouldYield and expose it through JSI.
For now we are only returning `false`. The value is backed by atomic_bool and in the future we will be able to indicate that React should yield to native.

JavaScript implementation:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L439-L441

Reviewed By: JoshuaGross

Differential Revision: D27648579

fbshipit-source-id: b9313e2efbd9daae8975357df9de803f24a35e89
2021-04-14 02:53:23 -07:00
Samuel Susla 08ef1df1ba Implement RuntimeScheduler::cancelTask
Summary:
Changelog: [internal]

Implement RuntimeScheduler::cancelTask and expose it through JSI.

JavaScript implementation:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L384-L397

Reviewed By: mdvacca

Differential Revision: D27648071

fbshipit-source-id: 91ae92b336017596fb658831824e971c7e047cd2
2021-04-13 01:55:04 -07:00
Samuel Susla 2779129434 Add minimal implementation of RuntimeScheduler::scheduleTask
Summary:
Changelog: [internal]

Add minimal implementation of schedule task. More features and proper scheduling will be added later.

Reviewed By: mdvacca

Differential Revision: D27622138

fbshipit-source-id: b2e4623d38e7217290a6a3c59ccc10a1c13e3a4f
2021-04-13 01:55:04 -07:00
Samuel Susla eb13baf2a6 Introducing RuntimeScheduler module
Summary:
Changelog: [internal[

Introducing RuntimeScheduler. A coordinator of work between native and React.

Reviewed By: mdvacca

Differential Revision: D27616818

fbshipit-source-id: e90d3d9ca8907be99e61f69e62e83cece8155050
2021-04-08 04:07:34 -07:00