Live data from Hacker News

Effectively Managing Memory at Gmail Scale

html5rocks.com

41–50 of 50 posts

Re: Effectively Managing Memory at Gmail Scale

#41

> Anecdotes of Gmail tabs consuming multiple gigabytes of memory on resource-constrained laptops and desktops were being heard increasingly frequently You know, I think I recall being able to run quite nicely featured GUI mail clients and IRC clients simultaneously on a Pentium 90 with 16 megs of RAM. And, I expect those clients had an order of magnitude less developer effort put into them compared to the GMail clien…

I don't think it normally does. I think what probably happens is that there are memory leaks. The longer you leave the tab open, the more memory it ends up consuming.

There's also the fact that it runs in the browser, which can make it more difficult to control or understand how many resources will be used.

Re: Effectively Managing Memory at Gmail Scale

#42

> Anecdotes of Gmail tabs consuming multiple gigabytes of memory on resource-constrained laptops and desktops were being heard increasingly frequently You know, I think I recall being able to run quite nicely featured GUI mail clients and IRC clients simultaneously on a Pentium 90 with 16 megs of RAM. And, I expect those clients had an order of magnitude less developer effort put into them compared to the GMail clien…

I often make this kind of argument as well, but the demands we put an email client through these days are nowhere near what such a machine could handle.

I have around 80.000 messages in my inbox, most of them with attachments around 10MB, and I can browse and search them instantly.

Then again, I mostly use Gmail's backend, my preferred interface is Mail.app

Re: Effectively Managing Memory at Gmail Scale

#43

Gmail still slow. Unrelated: Why haven't Google implemented a Google.com-quality-level search for email?

Last I checked, Gmail didn't do partial word searches. So “NewClient” won't match “GreatNewClient”. I think that's what rokhayakebe means.

It's one of the reasons I only use its backend. It baffles me that a company known for search can't do it.

Re: Effectively Managing Memory at Gmail Scale

#44

Gmail still slow. Unrelated: Why haven't Google implemented a Google.com-quality-level search for email?

When dealing with the public web, a search engine makes a single index of the web that millions of users can hit to perform searches. That amortizes the costs of generating and maintaining the index over a lot of people.

Your email corpus is private and specific to you. If Google (or any other company) generated a high-quality search index for it, they'd spend a lot of CPU hours on it and only amortize that across a single user: you.

Re: Effectively Managing Memory at Gmail Scale

#45
post #35

Earlier quoted context omitted.

As I said: a pauseless GC with a smart language implementation would be fine. ARC can work, but either requires programmers to prevent loops or needs a GC regardless. Object pools at the language level would be an alternative. (I.e. every object is allocated in a "pool", including pools. When a pool falls out of scope the entire pool is "freed". You can copy objects between pools as necessary.)

> Object pools at the language level would be an alternative. (I.e. every object is allocated in a "pool", including pools. When a pool falls out of scope the entire pool is "freed". You can copy objects between pools as necessary.) This might be called "memory regions" in the literature, or at least the work on using this memory management scheme in an ML (ML Kit).

Also related to arenas - the main difference is that an arena is a block region of memory from which different-sized objects are allocated, while a pool is a collection of same-sized objects. Both are pretty common techniques in C, C++, and Ada, and pools are common in high-performance Java.

Re: Effectively Managing Memory at Gmail Scale

#46

Earlier quoted context omitted.

Smart pointers won't save you. Yes, they'll eliminate the need for collection, by moving the overhead from a single collection to ever construction/destruction. This may be worth it to get a constant framerate, but the overhead doesn't disappear. If anything, it could be greater: allocating from the heap usually costs more than an object allocation done by any sane VM.

Constant framerate, even with overhead, can be preferable to random slowdowns.

The way you guarantee constant framerate in both a GCed or manual environment is the same: arenas/regions/pools/buffers. Manual memory management is susceptible to memory fragmentation, which can severely slow down allocation.

Re: Effectively Managing Memory at Gmail Scale

#47
post #17

Earlier quoted context omitted.

So basically one needs to re-implement smart pointers in Javascript, right ? What are the alternative to js style GC,for a language that wouldnt want to the developper to use manual memory allocation.I've heard about ARC.Are there other known architectures?

As I said: a pauseless GC with a smart language implementation would be fine. ARC can work, but either requires programmers to prevent loops or needs a GC regardless. Object pools at the language level would be an alternative. (I.e. every object is allocated in a "pool", including pools. When a pool falls out of scope the entire pool is "freed". You can copy objects between pools as necessary.)

Or just a smart language implementation. Go makes it easier to avoid heap allocation, and thus GC, since it allows you to specify if a structure resides on the heap or stack.

Re: Effectively Managing Memory at Gmail Scale

#48

> Game developers, take note: to ensure a 16ms frame time (required to achieve 60 frames per second), your application must make zero allocations, because a single young generation collection will eat up most of the frame time. And this is why GC isn't the be-all and end-all solution to memory management. (As as for people that are screaming "pauseless GC" - it has throughput issues [generally due to fine grained loc…

> Now, if someone combined a pauseless GC with proper cleanup (i.e. skipping GC altogether) of variables where the compiler could determine when they can be thrown away, matters would be different. (So, in other words, the compiler inserts `malloc` (or whatever) calls, and ensures that every variable created is either `free`d exactly once after it becomes unreachable or is added to the set tracked by the GC (or is a constant - especially pertinent with strings). With (hidden) local variables to track control flow when different branches cause different allocations.)

Freeing is not an issue, you don't pay for garbage in a proper GC, as the GC only scans living objects, and never frees.

The problem is allocation, as a scan is triggered when a certain number of bytes has been allocated. Go allows you to skip allocating on the heap (thus the GC), since you can define what is allocated on the stack or heap.

You potentially could do as you propose, by inserting "free" at certain points where you could prove the variable was safe to throw away. Free would basically just then say "you can now postpone allocation, you have more free memory". But this has it's own drawbacks. For one you a minimal amount more to do (calling 'free'), but more importantly you will increase time spent in allocation objects, because you have to scan the heap for available space instead of just bumping a pointer.

The most important thing is allowing the programmer a way to avoid the managed heap, which Go does, and C# to some degree does through structs.

Re: Effectively Managing Memory at Gmail Scale

#49
post #20

Earlier quoted context omitted.

> And this is why GC isn't the be-all and end-all solution to memory management. At least a GC knows where your memory blocks are and doesn't double free them. > Now, if someone combined a pauseless GC with proper cleanup (i.e. skipping GC altogether) of variables where the compiler could determine when they can be thrown away, Have you ever looked into ParaSail, Rust, ATS?

> At least a GC knows where your memory blocks are and doesn't double free them. Wrong. Counterexample: https://mail-archives.apache.org/mod_mbox/subversion-users/2... (Obtained by a quick search of "garbage collector double-free bug" - there are many others out there) > Have you ever looked into ParaSail, Rust, ATS? ParaSail and Rust don't have a GC, period, AFAIK. ATS is too strict for my liking. (I want a programm…

>Obtained by a quick search of "garbage collector double-free bug" - there are many others out there

Yeah, a bug.

I'd rather worry about double free being the case of a GC bug -- in a shared core code that can be fixed and the problem will vanish for everyone -- than in anywhere I have to free memory myself.

Re: Effectively Managing Memory at Gmail Scale

#50
post #25

Earlier quoted context omitted.

> Wrong..... I don't touch Perl since 2004. Back then it used reference counting, not a GC. Second, the post reads like a problem in the C code. > ParaSail and Rust don't have a GC, period, AFAIK. ATS is too strict for my liking. I was replying about GC alternatives for automatic memory management.

> the post reads like a problem in the C code. Exactly. All GC does is push down the code that can cause problems like double-frees into the language implementation. It doesn't magically make problems like double-free bugs impossible, like so many people say. > I was replying about GC alternatives for automatic memory management. Then why did you respond to and quote something that was talking about something entirel…

>Exactly. All GC does is push down the code that can cause problems like double-frees into the language implementation. It doesn't magically make problems like double-free bugs impossible, like so many people say.

That's like saying moving the likelihood of an event from 1/100 to 1/10000000, and only under very specific pre-conditions that are easily detactable, doesn't make it impossible.

That is, you are technically correct, which is the worst kind of correct.

The difference between double-free bugs in stuff "pushed down in the language implementation" and double-free bugs in programmer's own code is so huge, it's a total game changer.

Post reply on HN