[tracker/wip/carlosg/update-perf: 52/72] core: Replace hashtable with list




commit 3166c67e4de5e0393f794291a51a0b93238dcfe6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 18 16:21:09 2022 +0200

    core: Replace hashtable with list
    
    When preparing update statements, we can possibly end up with multiple
    coalesced single-valued property updates for the same property. In that
    case we attempt to just push the last update as it is the one that will
    prevail.
    
    But the amount of properties to be grouped for a same graph/resource/class
    tuple is not usually high enough. As this is a very hot path during
    updates, using a hashtable to track and avoid repeatedly updating the
    same property has an intrinsic cost that timidly shows up in profiles.
    
    As the amount of elements to iterate is not too high, this can be replaced
    with a GList which esentially drops these lookups from showing in profiles.

 src/libtracker-sparql/core/tracker-data-update.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c 
b/src/libtracker-sparql/core/tracker-data-update.c
index 2fcd70f16..8dfa15a91 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -1143,14 +1143,12 @@ tracker_data_flush_log (TrackerData  *data,
                                                         entry->table.multivalued.change_idx);
                        statement_bind_gvalue (stmt, 1, &property_entry->value);
                } else {
-                       GHashTable *visited_properties;
+                       GList *visited_properties = NULL;
                        gint param, property_idx;
 
                        tracker_db_statement_bind_int (stmt, 0, entry->id);
                        param = 1;
 
-                       visited_properties = g_hash_table_new (NULL, NULL);
-
                        property_idx = entry->table.class.last_property_idx;
 
                        while (property_idx >= 0) {
@@ -1161,7 +1159,7 @@ tracker_data_flush_log (TrackerData  *data,
                                                                 property_idx);
                                property_idx = property_entry->prev;
 
-                               if (g_hash_table_contains (visited_properties, property_entry->property))
+                               if (g_list_find (visited_properties, property_entry->property))
                                        continue;
 
                                if (G_VALUE_TYPE (&property_entry->value) == G_TYPE_INVALID) {
@@ -1171,10 +1169,10 @@ tracker_data_flush_log (TrackerData  *data,
                                        statement_bind_gvalue (stmt, param++, &property_entry->value);
                                }
 
-                               g_hash_table_add (visited_properties, property_entry->property);
+                               visited_properties = g_list_prepend (visited_properties, 
property_entry->property);
                        }
 
-                       g_hash_table_unref (visited_properties);
+                       g_list_free (visited_properties);
                }
 
                tracker_db_statement_execute (stmt, &inner_error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]