How I Hire Pole Dance Instructors

In the 14 months since I opened San Francisco Pole and Dance, our instructor team has grown from 6 to 18 people. Of all the various things that take time during the week — course curriculum…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Web Workers

Multi-threading in frond-end JavaScript

Web workers allow the tasks to be performed out of the UI thread. JavaScript which renders the UI for the client runs on a single thread. Which means a web page with several JavaScript tags means a huge TODO list for the browser and in a single thread. Having a Web Worker will let the browser dispatch a new Kernel Level thread thus by executing tasks without lagging the UI.

Modern web is highly interractive which means there are large number of background tasks to be performed in order to have the UI up to date. Following are several such applications where heavy tasks (Not essentially computationally expensive, but tasks that take time) requires spawning a new thread.

Web workers enables mobile applications that run JavaScript with HTML as their UI to perform tasks in background. Most of the transitions are JavaScript based and use of Web Workers enable such applications to utilize more of the Cores to perform.

Web workers run on a separate thread apart from the UI. Thus they do not have access for the following components

Therefore web workers shall be used with care for just the right purpose. Having too many will case the browser to occupy more of RAM and CPU time.

Communication architecture

Communication is done through message passing to the Web Worker and vice versa.

This is a simple implementation of a web worker. The worker performs a square root calculation of numbers from 0–1,000,000,000 and returns the time consumed. This is a simple demonstration of a time consuming task. Usually square root calculation takes a bit of time and time increases as the number increases.

The console will output the following

Add a comment

Related posts:

Is Positive Hacktivism Real?

In an era now of unprecedented connectivity between people and information over the digital network, the possibilities of social activism and participation have expanded into something completely…

Data is the new water

Such is its value and importance to driving the global economy, it has often been said that data is the new oil. But it is an imperfect comparison: oil is scarce and finite whereas data is an…

Free Carbon Footprint Calculator In Javascript

Do you need a carbon footprint calculator API? In this post, we’ll show you how to utilize one to calculate CO2 emissions in javascript. As the world economy rebounded swiftly from the Covid-19…