Commit 363acb1e authored by Iustin Pop's avatar Iustin Pop
Browse files

Optimizie OpCode loading

This patch converts the opcode loading to a pre-built map (at import
time) instead of iteration over the globals dict at each call.

Microbenchmarks show that this should be around three times faster, and
burnin still passes.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent b0c63e2b
......@@ -142,14 +142,9 @@ class OpCode(BaseOpCode):
raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
op_id = data["OP_ID"]
op_class = None
for item in globals().values():
if (isinstance(item, type) and
issubclass(item, cls) and
hasattr(item, "OP_ID") and
getattr(item, "OP_ID") == op_id):
op_class = item
if op_class is None:
if op_id in OP_MAPPING:
op_class = OP_MAPPING[op_id]
raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
op = op_class()
......@@ -578,3 +573,7 @@ class OpTestAllocator(OpCode):
"mem_size", "disks", "disk_template",
"os", "tags", "nics", "vcpus", "hypervisor",
OP_MAPPING = dict([(v.OP_ID, v) for v in globals().values()
if (isinstance(v, type) and issubclass(v, OpCode) and
hasattr(v, "OP_ID"))])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment