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.
This commit is contained in:
George Marques committed 2023-07-28 13:08:21 -03:00
1 parent 202e4b2c1e
commit c1bca65d09
4 files changed
+78 -21

No files matched your search

+2 -1
View File
@@ -113,6 +113,7 @@ void GDScriptFunction::disassemble(const Vector<String> &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<String> &p_code_lines) const {
text += " ";
text += DADDR(2);
incr += 5;
incr += 7 + _pointer_size;
} break;
case OPCODE_OPERATOR_VALIDATED: {
text += "validated operator ";