Beyond caching: Google engineers reveal secrets to faster websites

Joab Jackson@Joab_Jackson

In the fiercely competitive world of Internet services, Google constantly seeks ways to speed up the delivery of content to its hundreds of millions of users.

At the O’Reilly Velocity conference this week in New York, two Google engineers presented some of their favorite tips and research for expediting delivery of web pages and applications. Such knowledge could be handy for other web developers looking to make their products more responsive.

Google developer advocate and performance expert Colt McAnlis tackled one of the thorniest problems for mobile web developers today: JavaScript performance.

Web-based JavaScript applications can suffer from performance issues, especially on mobile clients, because JavaScript parsing engines use garbage collection (GC) to manage memory. “You shouldn’t rely on garbage collectors,” McAnlis told the audience of web developers.

GC helps programmers by automatically returning to the operating system the memory a program no longer needs. Writing code to manage memory in low-level languages such as C and C++ is a laborious process, though, and such languages aren’t natively supported by browsers anyway.

The problem with many JavaScript web apps is that JavaScript engines will launch their garbage collection routines at seemingly random times, which will cause applications to momentarily slow down. The frame rate of a video application, for instance, may decrease. Or the time it takes an application to execute an operation may jump to a noticeable 20 milliseconds, up from a typical 3-to-5 milliseconds.

Overall, for GC to work without being noticed by the user, the system memory must be six times as large as the amount of memory being used, said McAnlis, referring to a well-known study. This can be a demanding requirement given the limited memory of mobile devices and the number of memory-hungry applications they run. Read more of this post