Performance Tip : Learning to Think Beyond the Main Thread (VIDEO)

Published on November 30, 2019

Use-Cases of this video

  • Know how to improve performance of web applications.
  • Know why it is necessary to not execute all Javascript code on the browser's main thread.
  • Know why testing webapps on feature phones brings a whole new dimension towards performance.

If Javascript code executed on the main thread could be offloaded to several Web Workers, then performance problem of a web application would be solved almost completely.

A webapp's performance is mainly impacted due to the reason that almost all code is targeted to run on the main browser thread. The main thread is left to handle animations, rendering user interfaces, performing logic and computations.

Web Workers can allow code to run in parallel. However they don't have access to the DOM, so they are not able to render user interfaces. Web Workers created a lot of buzz when they were introduced, however they are highly underused in the current real world scenario.

Current Thinking Process of a Web Developer

The fact is that most web developers, even experienced ones, don't think about parallelism while creating the application. Sure they may be knowing and implementing newer browser APIs like async, defer, prefetch, Promises etc, but the fact is that they are just APIs. They may be efficient, but they are no replacement for a parallelism-based application design.

New Thinking Must Consider Parallelism as Compulsory

Web developers need to think about parallelism and threads from the very start of creating a new application. Surely Web Workers cannot render UI, but developers need to think how they can offload maximum computational code to the Worker. The "core" of the UI would be prepared by the Worker, while the UI would be rendered by the main thread.

Even if they can offload 50% of the work to a Worker, that is great. That small change may not boost performance, but multiple such small improvements will tremendously boost performance of the application.

Competition in general is increasing around the world. Performance is now moving from a state of "may have" to a "must have". Google search engine gives preference to faster web pages — this directly means that being faster will lead to more earnings. Expectations of users from webapps are increasing. They want "this", they want "that", and then they want "that" too.

Web developers will need to step up. The fact remains that although Web Workers have their limitations, they can still boost performance by a huge margin.

Below is a video presented in Chrome Dev Summit 2019. It is highly informative, and tells that why it is necessary to move code away from the browser's main thread, and offload them to Web Workers.

Useful Resources

In this Tutorial