From: Ian Romanick <ian.d.roman...@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.
Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2 by 225KiB on 64-bit. Before: IR MEM: variable usage / name / total: 5746368 1439077 7185445 After: IR MEM: variable usage / name / total: 5746368 1208630 6954998 Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2 by 70KiB on 32-bit. Before: IR MEM: variable usage / name / total: 4327584 915817 5243401 After: IR MEM: variable usage / name / total: 4327584 844096 5171680 Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> --- src/glsl/ir.cpp | 11 ++++++++++- src/glsl/ir_memory_usage.cpp | 3 ++- src/glsl/ir_validate.cpp | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 4907b34..69a0345 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -1536,7 +1536,16 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name, : ir_instruction(ir_type_variable), max_ifc_array_access(NULL) { this->type = type; - this->name = ralloc_strdup(this, name); + + 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); + } + this->data.explicit_location = false; this->data.has_initializer = false; this->data.location = -1; diff --git a/src/glsl/ir_memory_usage.cpp b/src/glsl/ir_memory_usage.cpp index 68c0b5c..4918824 100644 --- a/src/glsl/ir_memory_usage.cpp +++ b/src/glsl/ir_memory_usage.cpp @@ -63,7 +63,8 @@ ir_memory_usage::visit(ir_variable *ir) this->s.variable_usage += (sizeof(ir_state_slot) * ir->num_state_slots) + ralloc_header_size; - this->s.variable_name_usage += strlen(ir->name) + 1 + ralloc_header_size; + if (ir->name != (char *) ir->padding) + this->s.variable_name_usage += strlen(ir->name) + 1 + ralloc_header_size; return visit_continue; } diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index 1cfd0d5..08dd250 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -634,7 +634,7 @@ ir_validate::visit(ir_variable *ir) * in the ir_dereference_variable handler to ensure that a variable is * declared before it is dereferenced. */ - if (ir->name) + if (ir->name && ir->name != (char *) ir->padding) assert(ralloc_parent(ir->name) == ir); hash_table_insert(ht, ir, ir); -- 1.8.1.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev