Skip to content
Permalink
Browse files

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 46e572a497166a7dd0cd1ce99b5e0e2e8f5639af
Showing with 2 additions and 1 deletion.
  1. +2 −1 components/style/gecko_string_cache/mod.rs
@@ -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) }
}

0 comments on commit 46e572a

Please sign in to comment.
You can’t perform that action at this time.