Let the Main Thread Breathe!

Rate this content
Bookmark

The main thread, on the web, has a lot of responsibilities. At the same time, web apps are getting more sophisticated every day. Therefore, the main thread gets too busy that will disappoint our user showing janky frames! The off-main-thread architecture ensures apps run smoothly on every device for everyone.


In this talk, we will go through the possibilities in browsers such as WebWorker, Worklet, and WebAssembly introducing practical tools that allow us to boost our user experiences.

This talk has been presented at React Summit 2020, check out the latest edition of this React Conference.

FAQ

Around 50% of the world's population is connected to the Internet.

Approximately 90% of people access the Internet via their mobile phones.

Developers need to consider different device specifications to ensure their applications run smoothly across various devices, including low-spec hardware, thus providing a better user experience and avoiding unresponsive pages.

Web Workers are a browser feature that allows JavaScript to run in the background on a separate thread, preventing the main thread from being blocked and improving application performance.

WebAssembly is a binary instruction format that allows code written in languages like C, C++, and Rust to run on the web with near-native performance, often used to handle performance-intensive tasks.

Developers should identify tasks that cause the main thread to block, such as heavy computations or synchronous operations, and consider moving these tasks to Web Workers to improve user experience and application performance.

The main thread handles tasks such as downloading and parsing JavaScript, styling, layout, painting, and compositing. It is responsible for maintaining a smooth user interface and ensuring the application runs at 60 frames per second.

AssemblyScript is a TypeScript-based language that compiles to WebAssembly, allowing developers familiar with TypeScript to write code that can run with near-native performance.

The Comlink library simplifies the use of Web Workers by providing a promise-based interface, making it easier to communicate with Web Workers and integrate them into modern JavaScript applications.

Developers can optimize applications for low-spec devices by offloading heavy computations and non-UI tasks to Web Workers or WebAssembly, ensuring the main thread remains free to handle user interactions smoothly.

Majid Hajian
Majid Hajian
35 min
17 Jun, 2021

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The video highlights the advantages of using WebAssembly and Web Workers to improve web application performance. WebAssembly offers almost seven times faster performance than JavaScript, making it ideal for tasks like transcoding live camera feeds to MP4 format. Developers can use Web Workers to offload heavy tasks from the main thread, ensuring a smoother user experience. AssemblyScript is recommended for JavaScript developers due to its familiar syntax and ease of use. The talk emphasizes testing applications on low-level devices to identify performance bottlenecks and suggests moving synchronous operations to Web Workers. Using tools like the comlink library can simplify communication between the main thread and Web Workers. The video also discusses the importance of considering various devices and specifications to ensure responsive applications. By optimizing performance and using multiple cores, developers can enhance reliability and UI responsiveness.
Available in Español: ¡Deja respirar al hilo principal!

1. Introduction to the Talk

Short description:

Let's talk about how we can hold off tasks from the main thread to other threads and improve the performance of our web applications. Around 50% of the population is connected to the Internet, and this number is constantly increasing. 90% of these users access the Internet through their mobile phones.

Microsoft Mechanics www.microsoft.com www.microsoft.com www.microsoft.com www.microsoft.com www.microsoft.com Hello, let's talk about how we can actually hold off some tasks from main thread to other thread and let the main thread breeze a little bit. So, actually the fact that I wrote this talk was going back to maybe two years ago when I was searching about like how many people around the world like connecting to the Internet. And I found out that around 50% of the population are connected. And when I came back again to the statistics I noticed that after maybe one in two years five more persons of the population are now connected more than what they are connected like two years ago. And interestingly, around 90% of these people are connected to Internet via their mobile phone. I mean, they're just checking our website, our web application via mobile phones.

2. Importance of Device Compatibility

Short description:

We need to care about all devices and all users, even if we're targeting a specific market. There are various phones and devices with different specifications that our users are connecting with. We must ensure that our complex applications are responsive and reliable, avoiding unresponsive pages that frustrate our users.

And when I'm talking about mobile phones I'm talking about a whole lot of different phones. It's not just a good quality phone like iPhone or like high-end, high-quality aspect hardwares, phones. It's also some phones that they are looking good, very fine but the hardware's are not as powerful as phones like iPhone, for instance.

For instance, Nokia 2. So people are connecting with these phones for sure and we are shipping our complex application to them every day. And in fact, when it comes to even desktops, we have different laptops with different specs and different desktop with different hardware. And time to time, when we ship our complex application, we show this unresponsive page to our user, which makes them so frustrated. So they don't like to see these unresponsive or unreliable pages. But it comes to our mind that what can we do, why we need to care? So what should we do? The thing is that we need to care about all of our users. We need to care about all devices. We need to care about everyone who is connected, even though you are actually shipping an application for like a local, let's say, a market, there are still some, you know, you need to probably get some status, but there are still some, you know, devices that you need to cover and you need to support.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced 2022React Advanced 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
Don't Solve Problems, Eliminate Them
React Advanced 2021React Advanced 2021
39 min
Don't Solve Problems, Eliminate Them
Top Content
Kent C. Dodds discusses the concept of problem elimination rather than just problem-solving. He introduces the idea of a problem tree and the importance of avoiding creating solutions prematurely. Kent uses examples like Tesla's electric engine and Remix framework to illustrate the benefits of problem elimination. He emphasizes the value of trade-offs and taking the easier path, as well as the need to constantly re-evaluate and change approaches to eliminate problems.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
Utilising Rust from Vue with WebAssembly
Vue.js London Live 2021Vue.js London Live 2021
8 min
Utilising Rust from Vue with WebAssembly
Top Content
In this Talk, the speaker demonstrates how to use Rust with WebAssembly in a Vue.js project. They explain that WebAssembly is a binary format that allows for high-performance code and less memory usage in the browser. The speaker shows how to build a Rust example using the WasmPack tool and integrate it into a Vue template. They also demonstrate how to call Rust code from a Vue component and deploy the resulting package to npm for easy sharing and consumption.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
Jotai Atoms Are Just Functions
React Day Berlin 2022React Day Berlin 2022
22 min
Jotai Atoms Are Just Functions
Top Content
State management in React is a highly discussed topic with many libraries and solutions. Jotai is a new library based on atoms, which represent pieces of state. Atoms in Jotai are used to define state without holding values and can be used for global, semi-global, or local states. Jotai atoms are reusable definitions that are independent from React and can be used without React in an experimental library called Jotajsx.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Web3 Workshop - Building Your First Dapp
React Advanced 2021React Advanced 2021
145 min
Web3 Workshop - Building Your First Dapp
Top Content
Featured WorkshopFree
Nader Dabit
Nader Dabit
In this workshop, you'll learn how to build your first full stack dapp on the Ethereum blockchain, reading and writing data to the network, and connecting a front end application to the contract you've deployed. By the end of the workshop, you'll understand how to set up a full stack development environment, run a local node, and interact with any smart contract using React, HardHat, and Ethers.js.
Remix Fundamentals
React Summit 2022React Summit 2022
136 min
Remix Fundamentals
Top Content
Featured WorkshopFree
Kent C. Dodds
Kent C. Dodds
Building modern web applications is riddled with complexity And that's only if you bother to deal with the problems
Tired of wiring up onSubmit to backend APIs and making sure your client-side cache stays up-to-date? Wouldn't it be cool to be able to use the global nature of CSS to your benefit, rather than find tools or conventions to avoid or work around it? And how would you like nested layouts with intelligent and performance optimized data management that just works™?
Remix solves some of these problems, and completely eliminates the rest. You don't even have to think about server cache management or global CSS namespace clashes. It's not that Remix has APIs to avoid these problems, they simply don't exist when you're using Remix. Oh, and you don't need that huge complex graphql client when you're using Remix. They've got you covered. Ready to build faster apps faster?
At the end of this workshop, you'll know how to:- Create Remix Routes- Style Remix applications- Load data in Remix loaders- Mutate data with forms and actions
Vue3: Modern Frontend App Development
Vue.js London Live 2021Vue.js London Live 2021
169 min
Vue3: Modern Frontend App Development
Top Content
Featured WorkshopFree
Mikhail Kuznetsov
Mikhail Kuznetsov
The Vue3 has been released in mid-2020. Besides many improvements and optimizations, the main feature of Vue3 brings is the Composition API – a new way to write and reuse reactive code. Let's learn more about how to use Composition API efficiently.

Besides core Vue3 features we'll explain examples of how to use popular libraries with Vue3.

Table of contents:
- Introduction to Vue3
- Composition API
- Core libraries
- Vue3 ecosystem

Prerequisites:
IDE of choice (Inellij or VSC) installed
Nodejs + NPM
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
JSNation 2023JSNation 2023
174 min
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
Top Content
Featured WorkshopFree
Alba Silvente Fuentes
Roberto Butti
2 authors
This SvelteKit workshop explores the integration of 3rd party services, such as Storyblok, in a SvelteKit project. Participants will learn how to create a SvelteKit project, leverage Svelte components, and connect to external APIs. The workshop covers important concepts including SSR, CSR, static site generation, and deploying the application using adapters. By the end of the workshop, attendees will have a solid understanding of building SvelteKit applications with API integrations and be prepared for deployment.