Skip to content

object: Cache known unresolvable properties

Philip Chimento requested to merge ptomato/gjs:302-negative-resolve-cache into master

Based on a patch by Daniel van Vugt. This adds a negative cache to the resolve mechanism. Since on any particular GObject class's prototype we know whether a name is resolved or not, by consulting the introspection information, we can cache the name when it is not resolved, so that the resolve operation can quickly move on to the next parent class's prototype.

The situation we are trying to avoid here, is looking up a property or method belonging to an ancestor class (e.g., GObject.prototype.notify) on an instance of a class that is many levels of inheritance deeper (e.g. some custom Gtk widget.) If you do myWidget.notify('foo'), then the name 'notify' will first be resolved on the instance (a no-op), then on the custom widget class prototype (with resolve_no_info), then on each parent (with resolve), consulting all implemented interfaces at each level, and finally resolve on GObject.prototype. Subsequent lookups will still walk through all the intermediate classes and interfaces every time, even though GObject.prototype now has the property. By using the negative cache, all the resolves on intermediate classes return early, and the interfaces are not consulted.

I don't believe it's necessary to ever invalidate the cache, since new methods and properties cannot be added to introspection information at runtime.

Closes: #302 (closed)

Merge request reports