Skip to content

Commit 692dcc3

Browse files
committed
[SYSTEMDS-3890] Fix opcode lookup performance regression
With the refactoring of all 100s of opcodes, a stale merge introduced a performance regression of the inner opcode lookup, where instead of using the lookup table, we made a scan of all opcodes. With the fix the runtime for looking up all ~350 opcodes reduced from 0.358ms to 0.004ms.
1 parent a914c0d commit 692dcc3

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/main/java/org/apache/sysds/common/Opcodes.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
package org.apache.sysds.common;
2121

2222
import org.apache.sysds.lops.*;
23-
2423
import org.apache.sysds.common.Types.OpOp1;
2524
import org.apache.sysds.hops.FunctionOp;
2625

27-
import java.util.EnumSet;
2826
import java.util.HashMap;
2927
import java.util.Map;
3028

@@ -390,8 +388,8 @@ public enum Opcodes {
390388

391389
BINUAGGCHAIN("binuaggchain", InstructionType.BinUaggChain),
392390

393-
CASTDTM("castdtm", InstructionType.Cast),
394-
CASTDTF("castdtf", InstructionType.Cast),
391+
CASTDTM("castdtm", InstructionType.Variable, InstructionType.Cast),
392+
CASTDTF("castdtf", InstructionType.Variable, InstructionType.Cast),
395393

396394
//FED Opcodes
397395
FEDINIT("fedinit", InstructionType.Init);
@@ -427,7 +425,7 @@ public enum Opcodes {
427425
private static final Map<String, Opcodes> _lookupMap = new HashMap<>();
428426

429427
static {
430-
for (Opcodes op : EnumSet.allOf(Opcodes.class)) {
428+
for (Opcodes op : Opcodes.values()) {
431429
if (op._name != null) {
432430
_lookupMap.put(op._name.toLowerCase(), op);
433431
}
@@ -456,19 +454,17 @@ public static InstructionType getTypeByOpcode(String opcode, Types.ExecType type
456454
if (opcode == null || opcode.trim().isEmpty()) {
457455
return null;
458456
}
459-
for (Opcodes op : Opcodes.values()) {
460-
if (op.toString().equalsIgnoreCase(opcode.trim())) {
461-
switch (type) {
462-
case SPARK:
463-
return (op.getSpType() != null) ? op.getSpType() : op.getType();
464-
case FED:
465-
return (op.getFedType() != null) ? op.getFedType() : op.getType();
466-
default:
467-
return op.getType();
468-
}
457+
Opcodes op = _lookupMap.get(opcode.trim().toLowerCase());
458+
if( op != null ) {
459+
switch (type) {
460+
case SPARK:
461+
return (op.getSpType() != null) ? op.getSpType() : op.getType();
462+
case FED:
463+
return (op.getFedType() != null) ? op.getFedType() : op.getType();
464+
default:
465+
return op.getType();
469466
}
470467
}
471468
return null;
472469
}
473470
}
474-

0 commit comments

Comments
 (0)