[Mesa-dev] [PATCH 1/4] glsl: Hash separately from searching and inserting

Thomas Helland thomashelland90 at gmail.com
Thu Jan 12 19:23:44 UTC 2017


_mesa_hash_table_search is one of our hottest functions 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  maps one refcount_entry per variable. For each
reference and assignment we end up searching the table. Then we look
the variable up in the table later on. This is obviously quite painfull. 
We should be able to just move the refcount_entry to a pointer in the
variable itself. Then there would be no hash table at all!
---
 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