After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 697379 - use a small, fast-to-iterate implementation of Map, MultiMap
use a small, fast-to-iterate implementation of Map, MultiMap
Status: RESOLVED OBSOLETE
Product: folks
Classification: Platform
Component: libfolks
git master
Other Linux
: Normal normal
: Unset
Assigned To: folks-maint
folks-maint
Depends on:
Blocks:
 
 
Reported: 2013-04-05 17:26 UTC by Simon McVittie
Modified: 2018-09-21 16:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
WiP: add and use FolksSmallMap, FolksSmallMultiMap (105.27 KB, patch)
2013-04-05 17:27 UTC, Simon McVittie
needs-work Details | Review

Description Simon McVittie 2013-04-05 17:26:52 UTC
Similar to Bug #653239, many of Folks' uses of Map and MultiMap have few keys and few values.

I've prototyped a C implementation similar to Folks.SmallSet, implemented in terms of a GArray<struct{void *, void *}>. It cuts 10% off my performance benchmark's time, but doesn't have proper test coverage, and probably still has implementation bugs (tests/eds/im-details fails).

Efficient things:

* Quite memory-efficient (could be made better by not storing unnecessary callbacks)

* Read-only views are about as efficient as they're going to get

* get_keys() on "single" maps is O(n) C code, returning a SmallSet

* map_iterator() is fast C code, although it still has to create a GObject per use, so it still accounts for about 3%

Inefficient things:

* Membership testing scales up poorly: it's O(n)

* As a result, adding/removing items is typically also O(n)

* Adding/removing items from a multi-map can be as bad as O(n**2) because it keeps entries with the same key together in iteration order

* Map.entries, Map.iterator() and Map.foreach() are never going to be efficient anyway, because they construct one GObject per item: I implemented Entry, entries and iterator() in Vala

* Map.values, MultiMap.values, MultiMap.all_keys are also Vala code, although they don't account for many calls anyway

Possible future enhancements:

* get_key_at(int i), get_value_at(int i) are not implemented yet: they won't have syntax support, but could be used anyway in hot paths

I don't think I'm going to be able to finish this immediately, so I'm attaching my work-in-progress here.
Comment 1 Simon McVittie 2013-04-05 17:27:26 UTC
Created attachment 240775 [details] [review]
WiP: add and use FolksSmallMap, FolksSmallMultiMap
Comment 2 GNOME Infrastructure Team 2018-09-21 16:02:02 UTC
-- 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/60.