nsPresShell::mStackArena takes up a lot of space permanently even though
it's only used as temporary storage in a couple of XUL layout methods.
Before this patch, sizeof(nsPresShell) is 552 making jemalloc allocate
a 1024 byte block for it. Additionally, mStackArena is a 4096 block
even when it's not actually used. (This is on 64-bit Linux)
With the patch, sizeof(nsPresShell) is 512, fitting exactly into a 512
jemalloc chunk. mStackArena is removed, so the total saving is 4.6kB.

Created attachment 620361[details][diff][review]
fix
The StackArena/StackBlock/StackMark code is verbatim copies, except that
I made StackArena completely private and AutoStackArena a friend to forbid
any direct use of StackArena.

I'm not sure the two places where this code is used really justifies its
existence. The only benefit I see is that it coalesces the alloc/free
of (presumably) many small objects, and it avoids the realloc copying in
nsTArray f.e. should we use that instead. Do we have some collection type
that use "roped" multiple buffers internally to avoid copying?

> Before this patch, sizeof(nsPresShell) is 552 ... (This is on 64-bit Linux)
Uhm, a Linux64 debug build to be exact, so the clown shoes on nsPresShell
is likely less of a problem in release builds, I'll check what the real
numbers are. The 4096 bytes mStackArena size should be accurate though --
those structs does not have DEBUG-only members.

The size of nsPresShell in an Opt build on Linux64:
before: sizeof=496 moz_malloc_size_of=504
after: sizeof=456 moz_malloc_size_of=456
so the total saving is (with the 4096 of mStackArena) 4144 bytes.
After shuffling fields around, and narrowing the size of some, I get:
sizeof=408 moz_malloc_size_of=408
I'll file a separate bug for that.

It seems we keep a few in the bfcache as well. Here's the results I get:
start up with 1 tab (about:home)
3 shells
load in that tab -- mozilla.com, about:home, ...
+1 for each page up to 6
create a new tab (about:home):
+1 (total 7)
loading in tab 2 -- mozilla.com, about:home, ...
+1 for each page up to 10