Reduce overhead of wrapped objects
Gjs is currently using std::set to keep track of all wrapped objects, however all literature I find seems to hint it:
- Is typically implemented by an R-B tree underneath
- Allocates each node separately by default.
This potentially brings quite some overhead per wrapped object, both in terms of insertion/removal complexity (std::set is logarithmic) and memory overhead. In gnome-shell it is pretty trivial to get those in the range of tens of thousands. Given we just perform insertions, removals and linear scans, it seems std::set is overkill for the purpose.
I did a patch that makes ObjectInstance a doubly linked list to other wrapped objects, linking and unlinking those is O(1), and I think at least halves the memory overhead per element. From a quick check with ps
, a nested gnome-shell uses ~7M less of RSS right after startup.