The Advent of Cooperative Scheduling into the JavaScript world.

Shukant Pal
The Startup
Published in
8 min readJun 10, 2019

--

The race has begun!

W3C has released a proposed standard to enable web applications to cooperatively schedule tasks. It is based around the requestIdleCallback function, which allows you to defer tasks into the background. This API can be leveraged to produce fluid animations while doing complex computations behind the scenes.

What is scheduling?

Scheduling allows concurrent tasks to share CPU time without actually running in parallel. It can be done in two ways — preemptively and cooperatively.

  • Preemptive Scheduling: This is now the de facto approach in all operating systems. This involves a privileged software, the kernel, that gives CPU time to tasks using an algorithm. It allocates a calculated amount of time to a task, after which it does a task switch. All of this is done transparently without the application layer noticing.
  • Cooperative Scheduling: Instead of a privileged kernel forcing task switches at uncertain times, cooperative scheduling involves application developers yielding CPU time. Tasks can yield CPU time by using an API saying, “I have taken enough CPU time, let’s catch up on other work”.

Why Cooperative Scheduling

Operating system don’t rely on cooperative scheduling since malware can take all the CPU time — tasks cannot be forced to yield CPU time. However, application developers use cooperative…

--

--