Changeset 9e83b15 for protocols/nogaim.c


Ignore:
Timestamp:
2018-07-03T05:58:47Z (6 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
c17d0af
Parents:
49ab3cb
git-author:
dequis <dx@…> (03-07-18 05:27:59)
git-committer:
dequis <dx@…> (03-07-18 05:58:47)
Message:

Add a hash table to speed up bee_user_by_handle()

This maintains a hash table next to the linked list, which results in
negligible additional memory usage (~300kb for 10k users) but allows
instant lookups.

This was a big problem with discord, which has huge user lists and joins
everyone to every channel. In my test, the GUILD_SYNC event for 10k-50k
user lists is now approximately 5 times faster.

This hash table based code is only used if handle_cmp is either
exact or case-insensitive string comparison (g_ascii_strcasecmp or
strcmp/g_strcmp0).

The old function that goes through the bee->users linked list is now
called bee_user_by_handle_slow() and used for protocols with unusual
handle_cmp functions - skimming through the code, just oscar.
May revisit this if it happens to more meaningful protocols.

The case-insensitive hashtable functions are copied from irssi, which is
also GPLv2. I renamed them from g_ to b_ (g_istr_equal to b_istr_equal)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r49ab3cb r9e83b15  
    298298{
    299299        struct im_connection *ic;
     300        GHashFunc fn_hash = NULL;
     301        GEqualFunc fn_equal = NULL;
    300302
    301303        ic = g_new0(struct im_connection, 1);
     
    304306        ic->acc = acc;
    305307        acc->ic = ic;
     308
     309        /* figure out if we have hashing functions compatible with handle_cmp */
     310        if (acc->prpl->handle_cmp == g_ascii_strcasecmp) {
     311                fn_hash = b_istr_hash;
     312                fn_equal = b_istr_equal;
     313        } else if (acc->prpl->handle_cmp == g_strcmp0 || acc->prpl->handle_cmp == strcmp) {
     314                fn_hash = g_str_hash;
     315                fn_equal = g_str_equal;
     316        }
     317
     318        /* only create the hash table if we found them */
     319        if (fn_hash && fn_equal) {
     320                ic->bee_users = g_hash_table_new_full(fn_hash, fn_equal, NULL, NULL);
     321        }
    306322
    307323        connections = g_slist_append(connections, ic);
     
    320336                        break;
    321337                }
     338        }
     339
     340        if (ic->bee_users) {
     341                g_hash_table_destroy(ic->bee_users);
    322342        }
    323343
Note: See TracChangeset for help on using the changeset viewer.