A need for speed: the path to a faster loading sequence
May 13th, 2008 | Published in Gmail (Google Mail)
Great performance has always been an obsession at Google and it's something that we think about and work on everyday. We want Gmail to be really fast, and we keep working on ways to make it faster. Gmail's architecture eliminates many of the delays in reading mail by employing techniques like prefetching, but recently we decided to take a close look at some other key parts of Gmail to see if we could speed things up.
One of the areas we worked on was the initial loading sequence: everything that happens behind the scenes between the time you press the "Sign in" button on the login page and the moment you land in your inbox. While the improvements we made won't resolve every "This is taking longer than usual..." message you might see when loading Gmail over a slow connection, we've seen a real reduction (up to 20%) in overall load time compared to when we started.
First, we listed every transaction between the web browser and Google's servers, starting with the moment the "Sign in" button is pressed. To do this, we used a lot of different web development tools, like Httpwatch, WireShark, and Fiddler, plus our own performance measuring systems. These tools all have useful features, although some are limited to working only with certain browsers. The Httpwatch plug-in for Internet Explorer was one that proved easy to use and provided us with most of the information we needed. It really helps that we can capture and save browser traces with it too.
We spent hours poring over these traces to see exactly what was happening between the browser and Gmail during the sign-in sequence, and we found that there were between fourteen and twenty-four HTTP requests required to load an inbox and display it. To put these numbers in perspective, a popular network news site's home page required about a 180 requests to fully load when I checked it yesterday. But when we examined our requests, we realized that we could do better. We decided to attack the problem from several directions at once: reduce the number of overall requests, make more of the requests cacheable by the browser, and reduce the overhead of each request.
We made good progress on every front. We reduced the weight of each request itself by eliminating or narrowing the scope of some of our cookies. We made sure that all our images were cacheable by the browser, and we consolidated small icon images into single meta-images, a technique known as spriting. We combined several requests into a single combined request and response. The result is that it now takes as few as four requests from the click of the "Sign in" button to the display of your inbox.
We hope that some of you have felt the change, but performance improvements often go unnoticed, and that's okay. We'll keep working to make Gmail faster -- there's a lot we're doing right now -- and we'll give periodic updates as we get improvements out. (And hopefully you'll notice some of them too.)