Skip to content
WebsiteHosting.com

concept Frontend & browsers

JavaScript tasks, microtasks and rendering opportunities

A browser can finish a JavaScript task and still have microtasks to run before rendering. Compare the end of that work with a target time to see why meeting the target is different from observing a paint.

Latest recorded source check · P0176

What it means

Finishing a JavaScript task does not trigger a paint. Before the browser’s event loop moves on to a possible rendering update, it processes queued work called microtasks. It keeps taking microtasks from the queue until the queue is empty. This part of the sequence is called a microtask checkpoint, and it can take longer than the task that preceded it.

Try it

Simulation: Start with a task that runs from 0 to 12 milliseconds (ms). The target for a possible rendering update is at 16 ms. That leaves 4 ms between the end of the task and the target. Is that enough time for the checkpoint?

JavaScript tasks, microtasks and rendering opportunities

Explain why microtasks can delay rendering even after a task ends

Simulation
Modeled outcome: Miss

Task plus microtask checkpoint extends beyond the target opportunity.

JavaScript tasks, microtasks and rendering opportunities: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Task, microtask checkpoint and target opportunity

Checkpoint

  1. End32 ms
  2. Over target16 ms
Task0–12 ms
Microtask work12–32 ms
Target opportunity16 ms
16 ms
032 ms

The fixture runs the stipulated finite microtask work after a task. A target marker is an illustrative opportunity, not a measured browser refresh or guaranteed paint.

Evaluated inputs

Required scenario evidence
provided
Current task duration
12 ms
Microtasks queued
5 count
Duration per microtask
4 ms
Next rendering opportunity target
16 ms

One task, finite microtask queue, stipulated target not browser frame guarantee; no actual scheduler.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

With five microtasks taking 4 ms each, the first microtask finishes at 16 ms. At the target, there are still four to go. The checkpoint ends at 12 + 5 × 4 = 32 ms, or 16 ms past the target. That 16 ms is a calculated overrun, not a measured paint delay.

Change only Microtasks queued from 5 to 1. The checkpoint now ends exactly at 16 ms: the model counts that as meeting the target, with 0 ms of overrun. Change the count to 0 and the checkpoint ends at 12 ms instead. In neither case does the model say a frame was painted. Reset restores the original inputs, including the five microtasks.

If you select missing for Required scenario evidence, the timing values are not used and the result is unknown. That is different from a known count of zero, which gives a calculable result. An invalid input, such as a fractional task duration, gives an input error rather than a timing result.

Why the queue can keep rendering waiting

The checkpoint does not just process a list frozen at the moment the task returns. Suppose the last queued microtask runs and queues another one. When the event loop checks the queue again, it finds work, so the checkpoint continues. If that keeps happening, later rendering work on that event loop can be starved: it never gets a turn because the checkpoint never finishes. The simulation shows the cost of a finite queue, not a queue that grows as it runs.

A Promise reaction is one way work enters this sequence. ECMAScript gives the host responsibility for scheduling Promise jobs and requires their scheduling order to be respected. In a browser, HTML specifies that those jobs are queued as microtasks. The Promise ordering rule does not set a browser’s rendering schedule or give a universal order for tasks from different sources.

With a 12 ms task and one 4 ms microtask, the checkpoint ends exactly at the illustrative 16 ms target. The model reports no delay; adding a second such microtask moves the end to 20 ms. Equality is a boundary of the toy calculation, not a claim that a real browser paints at that moment. The difference is the remaining work before a possible rendering opportunity.

In practice

When investigating a late visual update, look for the end of the task, the microtasks that follow it, and evidence of rendering in the same browser trace. In the example, stopping at the task’s end would make the interval from 12 to 16 ms look free. Following the first microtask shows that all 4 ms are already spoken for.

Keep callback timing separate from paint timing. A Promise reaction tells you that a microtask ran. A requestAnimationFrame callback tells you that the browser reached the callback step of rendering, not that it finished layout or painting. Even an empty microtask queue only removes one reason to wait; the browser still decides whether to update rendering. If the trace shows a callback but no corresponding paint observation, report the callback time and leave the paint time unknown.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Is a Promise callback a task?

A Promise reaction is scheduled as a microtask in the HTML event-loop integration, not as an ordinary task. It runs at an applicable microtask checkpoint; the lab illustrates one bounded queue sequence.

Can microtasks enqueue more microtasks?

Yes. A microtask can enqueue further microtasks, and the checkpoint can continue until the relevant queue is empty. Long microtask chains can delay later work.

Does requestAnimationFrame guarantee immediate paint?

No. Reaching an animation callback is not proof of a paint at that instant. The example ends a finite checkpoint at a target time; it does not schedule real frames or measure rendering.

Does this measure browser FPS?

No. The timeline uses stipulated durations and a rendering opportunity model. It does not observe a browser frame rate, compositor or device.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. WHATWG HTML: event loops

    Event loop processing model; Promise jobs; rendering steps. Promise jobs integrate with microtask checkpoints. Animation callbacks are part of rendering processing, and a callback does not establish that visible painting finished.

    Checked .

  2. ECMAScript draft: Executable code and execution contexts

    §9.5.5. ECMAScript delegates promise-job scheduling to the host and requires scheduling order to be respected. The HTML event loop defines browser-specific rendering opportunities.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.