Closed Bug 1362167 Opened 3 years ago Closed 3 years ago
Reduce size of gfx
Shaped Word and gfx Text Run classes by optimizing field sizes and arrangement
In gfxShapedText, the abstract base of gfxShapedWord and gfxTextRun, we have a couple of fields that can be reduced in size, leading to significant memory savings. In particular: - mFlags is a 32-bit field, but many of the bits are only needed for gfxTextRun (not for gfxShapedWord -- and we may have thousands of cached gfxShapedWord records hanging around), so it could be smaller; - mAppUnitsPerDevUnit is also a 32-bit field, but the value will never be more than a couple of hundred (for on a maximally-zoomed-out page on a low-dpi screen). Currently, in a 64-bit build, sizeof(gfxShapedText) is 32, because its members (including vtable pointer) account for 28 bytes, and alignment then bumps the size to 32. If we reduce mFlags and mAppUnitsPerDevUnit to 16 bits each, sizeof(gfxShapedText) will drop to 24, and the fields added by gfxShapedWord and gfxTextRun will start 8 bytes earlier. We'll need to add a second 16-bit flags field in gfxTextRun, to handle the textrun-specific flags that no longer fit in the base gfxShapedText.mFlags field, but by judicious arrangement of the fields, that doesn't contribute any extra size. The overall result of the patch I'm going to propose here is to reduce the total size of textrun objects (as reported by about:memory) for the single-page HTML spec by around 1MB. I have two patches here: first, splitting the 32-bit flags field into two 16-bit fields, and moving one of them to gfxTextRun; and second, changing the two flags fields (and corresponding variables, function params, etc) from generic unsigned-int values (easy to mix bits in the wrong field!) to strongly-typed enum classes. They're both rather large, but are pretty repetitive (semi-mechanical) for the most part; by design, they're not changing any behavior, just rearranging the bits for more efficient packing.
Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Attachment #8864638 - Flags: review?(jmuizelaar) → review+
Attachment #8864637 - Flags: review?(jmuizelaar) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/0cbf75382a9abb55be44e22cbc351e9214f4431f Bug 1362167 - Split gfxShapedText.mFlags into two 16-bit flags fields, and arrange storage more compactly to reduce size of gfxShapedWord and gfxTextRun objects. r=jrmuizel https://hg.mozilla.org/integration/mozilla-inbound/rev/ed010b85ea12896dd62015ae399e22d700f998e9 Bug 1362167 - Use strongly-typed enum classes instead of generic uint16_t fields for the gfxShapedText and gfxTextRun flags. r=jrmuizel
You need to log in before you can comment on or make changes to this bug.