GNOME Bugzilla – Bug 697381
create read-only views more lazily
Last modified: 2018-09-21 16:02:10 UTC
Folks has a lot of this pattern: private Thing _thing = new Thing (); private Thing _thing_ro = _thing.read_only_view; public Thing thing { get { return this._thing_ro; } set { this._thing = value; this._thing_ro = value.read_only_view; } } Replacing this with private Thing _thing = new Thing (); private Thing? _thing_ro = null; public Thing thing { get { if (this._thing_ro == null) this._thing_ro = this._thing.read_only_view; return (!) this._thing_ro; } set { this._thing = value; this._thing_ro = null; } } might well save a few percent on startup performance benchmarks.
Conversely, if we're creating read-only views of the same set repeatedly, giving the SmallSet a weak ref to the read-only view might be a win. When testing SmallMap/SmallMultiMap, _read_only_view() (the implementation of read_only_view for SmallSet) was called 137000 times, accounting for 7.68% of cycle-estimation in callgrind.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/folks/issues/61.