Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On JavaScript High Performance

You're reading from   Hands-On JavaScript High Performance Build faster web apps using Node.js, Svelte.js, and WebAssembly

Arrow left icon
Product type Paperback
Published in Feb 2020
Publisher Packt
ISBN-13 9781838821098
Length 376 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Justin Scherer Justin Scherer
Author Profile Icon Justin Scherer
Justin Scherer
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Tools for High Performance on the Web 2. Immutability versus Mutability - The Balance between Safety and Speed FREE CHAPTER 3. Vanilla Land - Looking at the Modern Web 4. Practical Example - A Look at Svelte and Being Vanilla 5. Switching Contexts - No DOM, Different Vanilla 6. Message Passing - Learning about the Different Types 7. Streams - Understanding Streams and Non-Blocking I/O 8. Data Formats - Looking at Different Data Types Other Than JSON 9. Practical Example - Building a Static Server 10. Workers - Learning about Dedicated and Shared Workers 11. Service Workers - Caching and Making Things Faster 12. Building and Deploying a Full Web Application 13. WebAssembly - A Brief Look into Native Code on the Web 14. Other Books You May Enjoy

Offloading work to a dedicated worker

Workers give us the ability to offload long-running, computationally-intensive tasks to the background. Instead of having to make sure our event loop is not filled with some type of heavy task, we can offload that task to a background thread.

In other languages/environments, this might look like the following (this is only pseudo-code and is not really tied to any language):

Thread::runAsync((data) -> {
for(d : data) { //do some computation }
});

While this works well in those environments, we have to start thinking about topics such as deadlock, zombie threads, read after write, and so on. All of these can be quite hard to comprehend and are usually some of the most difficult bugs that can be encountered. Instead of JavaScript giving us the capability of utilizing something like the preceding, they gave us workers, which give us another...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime