Skip to content
Commit 3ead5929 authored by Simon McVittie's avatar Simon McVittie
Browse files

Mostly avoid an expensive multi-map iteration pattern

If you have a MultiMap with, say, 100 keys each with 1 value, and you
iterate over it like this (pseudocode):

    for key in keys():
        values = get(key)
        for value in values:
            do something(key, value)

then you have constructed one GObject for the result of keys(), and
100 GObjects for the results of get() (because it returns a read-only
view). If you iterate it like this:

    iter = map_iterator()
    while iter.next():
        do something(iter.key(), iter.value())

there's only one extraneous GObject, the iterator itself.

When there are thousands of contacts, as in add-contacts-stress-test,
this really starts to matter.

This patch doesn't fix every use of get_keys() - some of them do
non-trivial work per key as well as per value, making it awkward to
convert to map_iterator() - but it's a start. It cuts 'user' CPU time
for IndividualAggregator quiescence for an e-d-s Google account with
2049 contacts (reading from cache) by around 3%.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=682903


Reviewed-by: default avatarPhilip Withnall <philip@tecnocode.co.uk>
[note added to HACKING as per Philip's review]
Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
parent 1e758bd6
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment