[Mesa-dev] [PATCH 7/7] glsl: Prehash in refcount hash table

Thomas Helland thomashelland90 at gmail.com
Thu Feb 2 20:57:33 UTC 2017


_mesa_hash_table_search is one of our hottest function according to perf.
Callgrind shows the refcounting as one of the major users of the
searching functions. We can reduce the pain by prehashing, so that we
avoid hash two times when inserting in the table.

On a short shader-db run (with validation disabled) it makes
1.2 million of 4.5 million calls to _hash_table_insert come from
the pre-hashed path.
---3<---
This pass, as far as I've been able to see from my limited time
investigating it, maps one refcount_entry per variable. For each
reference and assignment we end up searching the table. This is
obviously quite painfull. If my understanding is correct we could
move the refcount_entry to a pointer in the variable itself.
Then there would be no hash table at all, which should considerably
lower our overhead.
---
 src/compiler/glsl/ir_variable_refcount.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/ir_variable_refcount.cpp b/src/compiler/glsl/ir_variable_refcount.cpp
index 8306be10b9..bbb4c0ddd7 100644
--- a/src/compiler/glsl/ir_variable_refcount.cpp
+++ b/src/compiler/glsl/ir_variable_refcount.cpp
@@ -79,13 +79,16 @@ ir_variable_refcount_visitor::get_variable_entry(ir_variable *var)
 {
    assert(var);
 
-   struct hash_entry *e = _mesa_hash_table_search(this->ht, var);
+   uint32_t hash = this->ht->key_hash_function(var);
+
+   struct hash_entry *e =
+      _mesa_hash_table_search_pre_hashed(this->ht, hash, var);
    if (e)
       return (ir_variable_refcount_entry *)e->data;
 
    ir_variable_refcount_entry *entry = new ir_variable_refcount_entry(var);
    assert(entry->referenced_count == 0);
-   _mesa_hash_table_insert(this->ht, var, entry);
+   _mesa_hash_table_insert_pre_hashed(this->ht, hash, var, entry);
 
    return entry;
 }
-- 
2.11.0



More information about the mesa-dev mailing list