- Preface
- Who this book is for
- What you'll need
- How the book is organized
- Conventions
- A note on browsers
- Chapter 1: The Main Thread Problem
- Technical requirements
- One thread, many jobs
- Three ways out
- A map of the tools
- What the numbers will look like
- A word on the demos
- Summary
- Check your understanding
- Chapter 2: Dedicated Workers
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 3: Shared Workers
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 4: Service Workers
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 5: OffscreenCanvas
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 6: Atomics and SharedArrayBuffer
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 7: WebAssembly Threads
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 8: The Scheduler API
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 9: Origin Private File System
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Chapter 10: Observables
- Technical requirements
- The idea
- How it works
- Where it is used
- Building the demo
- Pitfalls and browser support
- Summary
- Check your understanding
- Appendix
- Browser support
- Running the demos
- Choosing a tool
- Glossary
- Further reading
- About the Author
Leanpub Header
Beyond the Main Thread
Workers, Shared Memory and Scheduling for JavaScript in the Browser
A page freezes when one long task holds the main thread. Here are the browser tools that keep that work out of the way, each measured in real Chrome.
Minimum price
$4.00
$5.00
You pay
Author earns
Buying multiple copies for your team? See below for a discount!
About
About the Book
A page freezes when one long task holds the main thread. This book covers the browser's tools for keeping that work out of the way: dedicated, shared and service workers, OffscreenCanvas, SharedArrayBuffer and Atomics, WebAssembly threads, the Scheduler API, the Origin Private File System, and Observables.
Each chapter explains one tool, shows where it is used, and builds a demo you can run. The timings come from measurements in real Chrome, and the code is in a download that goes with the book. Where a result was surprising, the book says so: plain JavaScript beat our hand written WebAssembly on a single thread, and moving work to a worker didn't make it faster at all.
Some of what the demos measure
- A 1.5-second job that freezes the page on the main thread, and the same job in a worker
- Four workers losing more than half their updates to one shared counter
- A crashed tab noticed in about 200 ms, where a
pagehidehandler never noticed - Eight threads rendering about six times faster than one, and a fixed split of the work taking twice as long as a shared counter
- 20,000 small file writes in about 70 ms instead of about 3.5 seconds
Who this book is for
Web developers who know JavaScript and want to keep their pages responsive. You don't need to have used workers or shared memory before.
Team Discounts
Team Discounts
Get a team discount on this book!
Up to 3 members
- Minimum price
- $47.00
- Suggested price
- $72.00
Up to 5 members
- Minimum price
- $76.00
- Suggested price
- $116
Up to 10 members
- Minimum price
- $133
- Suggested price
- $203
Up to 15 members
- Minimum price
- $190
- Suggested price
- $290
Up to 25 members
- Minimum price
- $285
- Suggested price
- $435
Author
About the Author
Sandeep Kumar Patel is a senior web developer with more than 17 years of experience building web applications in object-oriented JavaScript and JSON. In 2012 he founded tutorialsavvy, a programming blog that developers have been reading ever since.
He is GATE-2005 Information Technology (IT) qualified and holds a Master's degree from VIT University, Vellore.
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.
