Module style::parallel [] [src]

Implements parallel traversal over the DOM tree.

This traversal is based on Rayon, and therefore its safety is largely verified by the type system.

The primary trickiness and fine print for the above relates to the thread safety of the DOM nodes themselves. Accessing a DOM element concurrently on multiple threads is actually mostly "safe", since all the mutable state is protected by an AtomicRefCell, and so we'll generally panic if something goes wrong. Still, we try to to enforce our thread invariants at compile time whenever possible. As such, TNode and TElement are not Send, so ordinary style system code cannot accidentally share them with other threads. In the parallel traversal, we explicitly invoke |unsafe { SendNode::new(n) }| to put nodes in containers that may be sent to other threads. This occurs in only a handful of places and is easy to grep for. At the time of this writing, there is no other unsafe code in the parallel traversal.

Enums

DispatchMode

Controls whether traverse_nodes may make a recursive call to continue doing work, or whether it should always dispatch work asynchronously.

Constants

STACK_SAFETY_MARGIN_KB

The stack margin. If we get this deep in the stack, we will skip recursive optimizations to ensure that there is sufficient room for non-recursive work.

STYLE_THREAD_STACK_SIZE_KB

The minimum stack size for a thread in the styling pool, in kilobytes.

WORK_UNIT_MAX

The maximum number of child nodes that we will process as a single unit.

Functions

traverse_nodes

Enqueues |nodes| for processing, possibly on this thread if the tail call conditions are met.