Beyond Caching: Google engineers reveal secrets to faster Web sites

Posted: 19/10/2013 in General News

Better JavaScript memory management and HTML prefetching tags could make Web sites more responsive

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.

[ Learn how to work smarter, not harder with InfoWorld’s roundup of all the tips and trends programmers need to know in the Developers’ Survival Guide. Download the PDF today! | Keep up with the latest developer news with InfoWorld’s Developer World newsletter. ]

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 GC (garbage collection) 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 applications 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.

Add to this issue the increasing use of closures, a programmer-friendly technique of widening the availability of locally defined variables. jQuery, for instance, is a widely used JavaScript library that relies on closures and as a result, creates a lot of splurges in memory allocation.

“Closures scare me,” McAnlis said, referring to how unpredictable they can be in terms of the amount of memory they can consume.

To improve performance, and better manage memory, developers should use an approach similar to the one used by the middleware library Emscripten, which is being used to build high performance HTML5 Web games.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s