From c1bca65d09b78dafafc496dcf47782e30887cf6e Mon Sep 17 00:00:00 2001 From: George Marques Date: Fri, 28 Jul 2023 13:08:21 -0300 Subject: GDScript: Optimize operators by assuming the types This assumes that operators are called usually with the same type of operands as the first time. So it stores the types of the first run and if matched it uses an optimized path by calling the validated operator function directly. Otherwise it uses the regular untyped evaluator. With this change, if operators do use the same type they run quite faster. OTOH, if the types mismatch it takes longer to run than they would with the previous code. --- modules/gdscript/gdscript_disassembler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gdscript/gdscript_disassembler.cpp') diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp index ec1d0af329..438ec02740 100644 --- a/modules/gdscript/gdscript_disassembler.cpp +++ b/modules/gdscript/gdscript_disassembler.cpp @@ -113,6 +113,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { switch (opcode) { case OPCODE_OPERATOR: { + constexpr int _pointer_size = sizeof(Variant::ValidatedOperatorEvaluator) / sizeof(*_code_ptr); int operation = _code_ptr[ip + 4]; text += "operator "; @@ -125,7 +126,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { text += " "; text += DADDR(2); - incr += 5; + incr += 7 + _pointer_size; } break; case OPCODE_OPERATOR_VALIDATED: { text += "validated operator "; -- cgit v1.2.3