Skip to content


Browse files Browse the repository at this point in the history
Store nsDynamicAtom's chars after the end of the object.
This reduces memory usage because we only need one allocation instead of two
for the dynamic atom and its chars, and because we don't need to store a
refcount and a size. It precludes sharing of chars between dynamic atoms, but
we weren't benefiting much from that anyway.

This reduces per-process memory usage by up to several hundred KiB on my
Linux64 box.

One consequence of this change is that we need to allocate + copy in
DOMString::SetKnownLiveAtom(), which could make some things slower.

Bug: 1447951
Reviewed-by: froydnj
  • Loading branch information
nnethercote authored and emilio committed Jun 23, 2018
1 parent ce7b661 commit 46e572a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/style/gecko_string_cache/
Expand Up @@ -122,7 +122,8 @@ impl WeakAtom {
unsafe { u8_ptr.offset(string_offset) as *const u16 }
} else {
let atom_ptr = self.as_ptr() as *const nsDynamicAtom;
unsafe { (*(atom_ptr)).mString }
// Dynamic atom chars are stored at the end of the object.
unsafe { atom_ptr.offset(1) as *const u16 }
unsafe { slice::from_raw_parts(string, self.len() as usize) }
Expand Down

0 comments on commit 46e572a

Please sign in to comment.