High-Performance JavaScript [chapter]

Colt McAnlis, Petter Lubbers, Brandon Jones, Duncan Tebbs, Andrzej Manzur, Sean Bennett, Florian d'Erfurth, Bruno Garcia, Shun Lin, Ivan Popelyshev, Jason Gauci, Jon Howard (+8 others)
2014 HTML5 Game Development Insights  
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. High Performance JavaScript, the image of a short-eared owl, and related trade dress are trademarks of O'Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in
more » ... caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. TM This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 978-0-596-80279-0 [M] The techniques and approaches taught in this book address many different aspects of JavaScript, covering execution time, downloading, interaction with the DOM, page life cycle, and more. Of these topics only a small subset, those related to core (ECMAScript) performance, could be rendered irrelevant by advances in JavaScript engines, but that has yet to happen. The other topics cover ground where faster JavaScript engines won't help: DOM interaction, network latency, blocking and concurrent downloading of JavaScript, and more. These topics will not only continue to be relevant, but will become areas of further focus and research as low-level JavaScript execution time continues to improve. Preface | xiii JavaScript Loading Chapter 1, Loading and Execution, starts with the basics of JavaScript: getting code onto the page. JavaScript performance really begins with getting the code onto a page in the most efficient way possible. This chapter focuses on the performance problems associated with loading JavaScript code and presents several ways to mitigate the effects. Coding Technique A large source of performance problems in JavaScript is poorly written code that uses inefficient algorithms or utilities. The following seven chapters focus on identifying problem code and presenting faster alternatives that accomplish the same task. Chapter 2, Data Access, focuses on how JavaScript stores and accesses data within a script. Where you store data is just as important as what you store, and this chapter explains how concepts such as the scope chain and prototype chain can affect your overall script performance. Stoyan Stefanov, who is well versed in the internal workings of a web browser, wrote Chapter 3, DOM Scripting. Stoyan explains that DOM interaction is slower than other parts of JavaScript because of the way it is implemented. He covers all aspects of the DOM, including a description of how repaint and reflow can slow down your code. xiv | Preface Chapter 4, Algorithms and Flow Control, explains how common programming paradigms such as loops and recursion can work against you when it comes to runtime performance. Optimization techniques such as memoization are discussed, as are browser JavaScript runtime limitations. Many web applications perform complex string operations in JavaScript, which is why string expert Steven Levithan covers the topic in Chapter 5, Strings and Regular Expressions. Web developers have been fighting poor string-handling performance in browsers for years, and Steven explains why some operations are slow and how to work around them. Chapter 6, Responsive Interfaces, puts the spotlight firmly on the user experience. Java-Script can cause the browser to freeze as it executes, leaving users extremely frustrated. This chapter discusses several techniques to ensure that the user interface remains responsive at all times. In Chapter 7, Ajax, Ross Harmes discusses the best ways to achieve fast client-server communication in JavaScript. Ross covers how different data formats can affect Ajax performance and why XMLHttpRequest isn't always the best choice. Chapter 8, Programming Practices, is a collection of best practices that are unique to JavaScript programming.
doi:10.1007/978-1-4302-6698-3_3 fatcat:p5tifnxeq5h5rmgyhuyzxoxtxm