[Mesa-dev] [PATCH 24/26] glsl: Store short variable names inside ir_variable

Ian Romanick idr at freedesktop.org
Mon Jul 14 15:48:56 PDT 2014


From: Ian Romanick <ian.d.romanick at intel.com>

Most of the overhead of the name allocation is the ralloc tracking,
especially on 64-bit.  The allocation of the variable name "i" is 2
bytes for the name and 40 bytes for the ralloc tracking.

I collected data from shader-db.  At the end of link_shaders I added a
visitor to print the name of every ir_variable in every shader.  Out of
the 188,786 names logged, 47,636 were two characters or less (the size
that will fit in the padding on 32-bit builds) and 89,610 were six
characters or less (the size that will fit in the padding on 64-bit
builds).

Valgrind massif results for a trimmed apitrace of dota2:

                  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
Before (32-bit): 56 40,527,975,617       66,347,992       61,187,818     5,160,174            0
After  (32-bit): 52 40,521,071,734       66,157,928       61,054,870     5,103,058            0

Before (64-bit): 62 37,089,989,777       93,205,752       85,900,367     7,305,385            0
After  (64-bit): 48 37,089,379,412       92,630,712       85,454,539     7,176,173            0

A real savings of 129KiB on 32-bit and 435KiB on 64-bit.

The savings is much higher on 64-bit because ir_instruction::padding is
7 bytes (instead of 3 bytes on 32-bit).  This allows a lot more names to
fit in the padding.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ir.cpp | 5 +++++
 src/glsl/ir.h   | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index bc008a4..4b22439 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1559,6 +1559,11 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
    if (mode == ir_var_temporary
        && (name == NULL || name == ir_variable::tmp_name)) {
       this->name = ir_variable::tmp_name;
+   } else if (name == NULL) {
+      this->padding[0] = 0;
+      this->name = (char *) this->padding;
+   } else if (strlen(name) < sizeof(this->padding)) {
+      this->name = strcpy((char *) this->padding, name);
    } else {
       this->name = ralloc_strdup(this, name);
    }
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index ead0863..770fe60 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -598,7 +598,8 @@ public:
 
    inline bool is_name_ralloced() const
    {
-      return this->name != ir_variable::tmp_name;
+      return this->name != ir_variable::tmp_name
+         && this->name != (char *) this->padding;
    }
 
    /**
-- 
1.8.1.4



More information about the mesa-dev mailing list