Skip to main content

Minimize main thread work

Description

Web browsers traditionally consist of a main rendering thread that handles most of the updates on the web page and the execution of JavaScript. JavaScript is executed on the main thread to simplify JavaScript implementations so the JavaScript programmer doesn't have to deal with any multi-threading programming patterns. When doing long running JavaScript computations it is running single threaded. In contrast all CPUs nowadays have multiple cores which have to be powered on while being underutilized.

Solution

For long running JavaScript computations (e.g. computations that run longer than a few 100 ms) try to use WebWorkers and run them in another thread while keeping the main rendering thread free. Consider moving the JavaScript computation to efficient server implementations that use optimized algorithms.

SCI Impact

SCI = (E * I) + M per R
Software Carbon Intensity Spec

Concerning the SCI equation, minimize main thread work will impact as follows:

  • E: CPU resources can be used more efficiently which reduces the electricity required and reduces the carbon intensity

Assumptions

  • An assumption is made that the code in question can be moved of the main rendering thread

Considerations

  • Consider moving the workload to a efficient server implementation

References