Gmail Homepage’s Quota estimate
I was curious about how the quota counter on Gmail’s homepage (you know, the one before you log in, that’s updated every second) worked, so I had a quick look at the source, and it proved pretty interesting. First, it’s one of the few scripts I’ve seen from Google that’s not obfuscated. Then, it turns out they use linear interpolation between some past storage values and estimated future storage. The joke is that they have a storage estimate of Number.MAX_VALUE in Year 3456

A brilliant summary of how storage estimates evolved over time can be found on Zvi Devir’s page. He also points out the Sci-Fi inside joke comment in the interpolation array definition from the geeks over at Google: // Estimates of nanite storage generation over time.
And finally, a function called updateQuota() is called every second to change the quota value on the webpage via DOM scripting.
Another interesting thing in this script is how they get a value of Round-trip Time (RTT) between your browser and their server and store it in a cookie for future use. They do that by loading an image of size 0, and by looking at the time span between when they start to send it and after they receive it. Well, strictly speaking, depending on your connection’s bandwidth this estimate can be higher because you have to send all the bytes in the request and get all the bytes in the response (when strictly speaking RTT is for one Bit) but I guess the estimate is good enough that way. In my case Gmail’s RTT varies greatly, from values as low as 172ms to as high as 3s. For reference, the code they use is:
var ONE_PX = "https://mail.google.com/mail/images/c.gif?t=" +
(new Date()).getTime();
function LogRoundtripTime() {
var img = new Image();
var start = (new Date()).getTime();
img.onload = GetRoundtripTimeFunction(start);
img.src = ONE_PX;
}
function GetRoundtripTimeFunction(start) {
return function() {
var end = (new Date()).getTime();
SetGmailCookie("GMAIL_RTT", (end - start));
}
}
August 14th, 2009 at 4:05 am
hooi hoii
October 8th, 2010 at 6:12 am
The question about those aromatic advertisements that perfume companies are having stitched into magazines these days is this: under the freedoms guaranteed by the First Amendment, is smelling up the place a constitutionally protected form of expression? Calvin Trillin
November 1st, 2010 at 4:25 am
Thankyou for this informative piece. I look forward more of your writing on this topic sometime soon. Thanks again
January 17th, 2011 at 1:53 pm
With your talent, certainly you have heard praises before but I just want to add on to the many who have thanked you for what you’ve achieved. Your pieces are distinct and show great thought. Thanks for your pieces!
June 1st, 2011 at 10:23 pm
Hi, a friend of mine recommended Gmail Homepage’s Quota estimate | Blog - MapMyGlobe to me so I came to see it. I must say it is quite a website. You sure make me come back again. I have one question though. Is your theme a premium one and where can I find it? Thanks!
January 5th, 2012 at 10:04 pm
This is the fitting blog for anybody who wants to seek out out about this topic. You realize so much its almost exhausting to argue with you (not that I truly would want…HaHa). You undoubtedly put a new spin on a subject thats been written about for years. Great stuff, just nice!