I think there are potential memory savings in CSS computed styles; how about adding a UMA metric to see how much potential exists there? I have a hacky demo CL that reduces renderer private RAM usage by up to ~6.8% in extreme cases and ~0.47% on a Google search results page, at the cost of slightly increased CPU usage.
Hi!
I've been tinkering with some tooling (still unfinished, and I probably won't get around to finishing it anytime soon), and I've noticed that on some websites, objects related to CSS computed styles can consume a non-negligible chunk of RAM; and many of these objects have mostly or completely the same contents.
A very extreme example is
https://elixir.bootlin.com/linux/v5.10/source/mm/filemap.c (a source cross referencing website), where there are e.g. 20755 allocations of blink::ComputedStyleBase::StyleBoxData (plus a lot more in other blink::ComputedStyleBase::*). The contents of these objects look as follows; the stuff under "TOP VALUES" are hex dumps of the three most frequent values along with the number of instances of those values:
0x000 0x004 <inheritance> typeunit:WTF::RefCounted<[...]>
[...]
#### TOP VALUES:
#### 20743 01 00 00 00
#### 12 02 00 00 00
0x004 0x00c aspect_ratio_ typeunit:blink::StyleAspectRatio
0x004 0x004 type_ typeunit:unsigned int
#### TOP VALUES:
#### 20755 00 07 5f c0
0x008 0x008 ratio_ typeunit:blink::FloatSize
[...]
#### TOP VALUES:
#### 20755 00 00 00 00 00 00 00 00
#### TOP VALUES:
#### 20755 00 07 5f c0 00 00 00 00 00 00 00 00
0x010 0x010 contain_intrinsic_height_ typeunit:absl::optional<blink::StyleIntrinsicLength>
[...]
#### TOP VALUES:
#### 20755 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x020 0x010 contain_intrinsic_width_ typeunit:absl::optional<blink::StyleIntrinsicLength>
[...]
0x020 0x001 engaged_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x024 0x00c <unnamed member> typeunit:absl::optional_internal::[2:optional_data_dtor_base<blink::StyleIntrinsicLength, false>]<unnamed>
#### TOP VALUES:
#### 20755 00 00 00 00 00 00 00 00 00 00 00 00
[...]
#### TOP VALUES:
#### 20755 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x030 0x008 height_ typeunit:blink::Length
0x030 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 20741 00 00 00 00
#### 8 00 00 c8 42
#### 1 66 66 26 42
0x034 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x035 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 20741 00
#### 7 02
#### 7 01
0x036 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 20741 00
#### 14 01
#### TOP VALUES:
#### 20741 00 00 00 00 00 00 00 00
#### 7 00 00 c8 42 00 01 01 00
#### 1 66 66 26 42 00 02 01 00
0x038 0x008 max_height_ typeunit:blink::Length
0x038 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 20755 00 00 00 00
0x03c 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x03d 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 20755 0c
0x03e 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 20755 00
#### TOP VALUES:
#### 20755 00 00 00 00 00 0c 00 00
0x040 0x008 max_width_ typeunit:blink::Length
0x040 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 20753 00 00 00 00
#### 2 00 00 a5 43
0x044 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x045 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 20753 0c
#### 2 02
0x046 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 20753 00
#### 2 01
#### TOP VALUES:
#### 20753 00 00 00 00 00 0c 00 00
#### 2 00 00 a5 43 00 02 01 00
0x048 0x008 min_height_ typeunit:blink::Length
0x048 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 20751 00 00 00 00
#### 2 00 00 c8 42
#### 1 00 80 37 44
0x04c 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x04d 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 20751 00
#### 2 02
#### 2 01
0x04e 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 20751 00
#### 4 01
#### TOP VALUES:
#### 20751 00 00 00 00 00 00 00 00
#### 2 00 00 c8 42 00 01 01 00
#### 1 00 80 37 44 00 02 01 00
0x050 0x008 min_width_ typeunit:blink::Length
0x050 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 20755 00 00 00 00
0x054 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x055 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 20753 00
#### 2 02
0x056 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 20753 00
#### 2 01
#### TOP VALUES:
#### 20753 00 00 00 00 00 00 00 00
#### 2 00 00 00 00 00 02 01 00
0x058 0x008 width_ typeunit:blink::Length
0x058 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 16773 00 00 00 00
#### 3975 00 00 c8 42
#### 3 00 00 52 43
0x05c 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x05d 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 16773 00
#### 3976 01
#### 6 02
0x05e 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 16773 00
#### 3982 01
#### TOP VALUES:
#### 16773 00 00 00 00 00 00 00 00
#### 3975 00 00 c8 42 00 01 01 00
#### 3 00 00 52 43 00 02 01 00
0x060 0x008 vertical_align_length_ typeunit:blink::Length
0x060 0x004 <unnamed member> typeunit:blink::[2:Length]<unnamed>
#### TOP VALUES:
#### 20724 00 00 00 00
#### 31 cb 10 c7 3f
0x064 0x001 quirk_ typeunit:bool
#### TOP VALUES:
#### 20755 00
0x065 0x001 type_ typeunit:unsigned char
#### TOP VALUES:
#### 20724 00
#### 31 02
0x066 0x001 is_float_ typeunit:bool
#### TOP VALUES:
#### 20724 00
#### 31 01
#### TOP VALUES:
#### 20724 00 00 00 00 00 00 00 00
#### 31 cb 10 c7 3f 00 02 01 00
0x068 0x004 z_index_ typeunit:int
#### TOP VALUES:
#### 20747 00 00 00 00
#### 3 1d 00 00 00
#### 2 02 00 00 00
0x06c 0x004 box_decoration_break_ typeunit:unsigned int
0x06c 0x004 box_sizing_ typeunit:unsigned int
0x06c 0x004 has_auto_z_index_ typeunit:unsigned int
#### TOP VALUES:
#### 20742 05 00 00 00
#### 8 01 00 00 00
#### 3 2d 1c 00 00
Many of these objects have identical contents. This is a very extreme example; most websites have much less of these objects.
If you think that this is worth investigating, maybe it would be a good idea to add a UMA metric to track how much memory is spent on blink::ComputedStyleBase::* and blink::ComputedStyleBase instances, in absolute terms and as a fraction of renderer memory usage, or something along those lines? That might help determine how much effort it would be worth to design a proper optimization for this.