Skip to content

Commit e166cd9

Browse files
droewtdcode
andauthored
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 <[email protected]>
1 parent 1ba25de commit e166cd9

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

.github/workflows/build-uc2.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -471,26 +471,26 @@ jobs:
471471
generators: 'Ninja'
472472
}
473473
- {
474-
os: ubuntu-latest,
474+
os: ubuntu-22.04,
475475
arch: aarch64,
476476
python-arch: aarch64,
477477
python-ver: '3.8',
478478
name: 'ubuntu-aarch64 cmake',
479479
artifact: 'ubuntu-cmake-aarch64.7z',
480480
archiver: '7z a',
481481
generators: 'Ninja',
482-
distro: ubuntu20.04
482+
distro: ubuntu22.04
483483
}
484484
- {
485-
os: ubuntu-latest,
485+
os: ubuntu-22.04,
486486
arch: ppc64le,
487487
python-arch: ppc,
488488
python-ver: '3.8',
489489
name: 'ubuntu-ppc64le cmake',
490490
artifact: 'ubuntu-cmake-ppc64le.7z',
491491
archiver: '7z a',
492492
generators: 'Ninja',
493-
distro: ubuntu20.04
493+
distro: ubuntu22.04
494494
}
495495
compiler: [ gcc ]
496496
steps:

.github/workflows/build-wheels-publish.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ jobs:
5555
# x86_64 - musllinux
5656
- { os: ubuntu-latest, arch: x86_64, cibw_build: 'cp38-musllinux*', cibw_skip: '' }
5757
# aarch64 - manylinux
58-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-manylinux*', cibw_skip: '' }
58+
- { os: ubuntu-22.04, arch: aarch64, cibw_build: 'cp38-manylinux*', cibw_skip: '' }
5959
# aarch64 - musllinux
60-
- { os: ubuntu-latest, arch: aarch64, cibw_build: 'cp38-musllinux*', cibw_skip: '' }
60+
- { os: ubuntu-22.04, arch: aarch64, cibw_build: 'cp38-musllinux*', cibw_skip: '' }
6161
- { os: macos-13, arch: x86_64, cibw_build: 'cp38*', cibw_skip: '' }
6262
- { os: macos-latest, arch: arm64, cibw_build: 'cp38*', cibw_skip: '' }
6363
- { os: windows-2019, arch: AMD64, cibw_build: 'cp38*', cibw_skip: '' }

bindings/python/unicorn/unicorn_py3/arch/arm64.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def value(self) -> int:
3737
return self.val
3838

3939

40+
class CpReg(NamedTuple):
41+
crn: int
42+
crm: int
43+
op0: int
44+
op1: int
45+
op2: int
46+
val: int
47+
48+
4049
class UcAArch64(Uc):
4150
"""Unicorn subclass for ARM64 architecture.
4251
"""
@@ -57,14 +66,6 @@ def __hook_insn_sys():
5766
def __hook_insn_sys_cb(uc: Uc, reg: int, pcp_reg: Any, key: int) -> int:
5867
cp_reg = ctypes.cast(pcp_reg, ctypes.POINTER(UcRegCP64)).contents
5968

60-
class CpReg(NamedTuple):
61-
crn: int
62-
crm: int
63-
op0: int
64-
op1: int
65-
op2: int
66-
val: int
67-
6869
cp_reg = CpReg(cp_reg.crn, cp_reg.crm, cp_reg.op0, cp_reg.op1, cp_reg.op2, cp_reg.val)
6970

7071
return callback(uc, reg, cp_reg, user_data)

0 commit comments

Comments
 (0)