arm64 python: Avoid nested class in insn hook for 10x hook and 10% overall speedup (#2095)

* arm64 python: Avoid nested class in insn hook for 10x hook speedup

Promote CpReg to a module-level class to address unnecessary performance
reduction.  In a real-world use case tracing the emulation of real-world
machine code, this change reduces time spent in CpReg namedtuple
construction from 10% of overall time to below 1%, for a 10x speedup of
the insn hook itself, or a 10% overall speedup.  Measured using
cProfile, python 3.13.

* upgrade distro to 22.04

* revert to 22.04 for now

* also revert for wheels

---------

Co-authored-by: mio <mio@lazym.io>
This commit is contained in:
Daniel Roethlisberger
2025-02-10 07:56:34 +01:00
committed by GitHub
parent 1ba25def8e
commit e166cd93bb
3 changed files with 15 additions and 14 deletions

View File

@@ -37,6 +37,15 @@ class UcRegCP64(UcTupledReg[ARM64CPReg]):
return self.val
class CpReg(NamedTuple):
crn: int
crm: int
op0: int
op1: int
op2: int
val: int
class UcAArch64(Uc):
"""Unicorn subclass for ARM64 architecture.
"""
@@ -57,14 +66,6 @@ class UcAArch64(Uc):
def __hook_insn_sys_cb(uc: Uc, reg: int, pcp_reg: Any, key: int) -> int:
cp_reg = ctypes.cast(pcp_reg, ctypes.POINTER(UcRegCP64)).contents
class CpReg(NamedTuple):
crn: int
crm: int
op0: int
op1: int
op2: int
val: int
cp_reg = CpReg(cp_reg.crn, cp_reg.crm, cp_reg.op0, cp_reg.op1, cp_reg.op2, cp_reg.val)
return callback(uc, reg, cp_reg, user_data)