Skip to content

Refactor ObjectInstance, part 3 of 3

After a lot of preparation we finally have separate classes for the private data of ObjectInstance and ObjectPrototype. This should fix one of the regressions (#165 (closed)) from the previous two parts although probably not the other one (#171 (closed)), and clears the way towards rebasing the SpiderMonkey 60 branch (#161 (closed)).

We have a bit of an unorthodox way of doing polymorphism, see the commit messages for explanation.

I've also tacked on a couple of commits to reduce the space taken by both of these structs. Before the change, ObjectInstance was 128 bytes per object (plus another 32 if the object was in toggle ref mode, and toggled up), and ObjectPrototype was 288 bytes per GObject class (128 for the ObjectInstance struct, plus 160 for the prototype and field caches, allocated as GType qdata.) Now, ObjectInstance is 88 bytes (still plus 32 if toggled up), and ObjectPrototype is 192 bytes.

Possible improvements for the future could be:

  • Refactor closure.cpp to use only one GjsContext dispose notify for all closures, which would allow shrinking GjsMaybeOwned and therefore ObjectInstance by 24 bytes (I tried this but it wasn't obvious whether it would work);
  • Instead of using PersistentRooted in GjsMaybeOwned, trace all rooted GjsMaybeOwned structs from the global object, which would allow shrinking GjsMaybeOwned and therefore ObjectInstance by 8 bytes, and get rid of the 32 extra bytes when the object is toggled up.

Merge request reports