Chapter 5. Program Performance
This book so far has been all about how to leverage asynchrony patterns more effectively. But we haven’t directly addressed why asynchrony really matters to JS. The most obvious explicit reason is performance.
For example, if you have two Ajax requests to make, and they’re independent, but you need to wait on them both to finish before doing the next task, you have two options for modeling that interaction: serial and concurrent.
You could make the first request and wait to start the second request until the first finishes. Or, as we’ve seen both with promises and generators, you could make both requests in parallel, and ask the gate to wait on both of them before moving on.
Clearly, the latter is usually going to be more performant than the former. And better performance generally leads to better user experience.
It’s even possible that asynchrony (interleaved concurrency) can improve just the perception of performance, even if the overall program still takes the same amount of time to complete. User perception of performance is every bit—if not more!—as important as actual measurable performance.
We want to now move beyond localized asynchrony patterns to talk about some bigger picture performance details at the program level.
Note
You may be wondering about micro-performance issues, like if
a++
or ++a
is faster. We’ll look at those sorts of performance
details in Chapter 6.
Web Workers
If you have processing-intensive tasks but you don’t want ...
Get You Don't Know JS: Async & Performance now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.