Commit ab0a332
perf(core): cut per-call overhead in candidate scoring and hash sequences
Three related hot-path tweaks, all behavior-preserving:
1. SmdaFunction / SmdaBasicBlock: replace
`bytes([ord(c) for c in "".join(seqs)])` with
`"".join(seqs).encode("ascii")` in the four PIC/OPC hash sequence
helpers. The output is byte-identical (the escaper emits ASCII-only
strings), but the per-character Python loop is gone. Microbench on a
~3.7 KB escaped sequence shows ~600x speedup for the conversion step
alone; on the asprox fixture (105 funcs, 2140 blocks) block hash
sequence assembly drops ~15%.
2. FunctionCandidate: hoist
`sorted([int(k) for k in COMMON_PROLOGUES], reverse=True)` out of
`hasCommonFunctionStart` / `getFunctionStartScore` to a module-level
constant. Both methods are called from `calculateScore` /
`getCharacteristics` / `__str__` / `toJson`, so on every candidate
the prologue length list was being rebuilt and re-sorted from
scratch. calculateScore over 200k iterations drops from 322ms to
180ms (~44%) in a focused bench.
3. FunctionCandidate.call_ref_sources: switch from list to set. The
inner CFG-recovery loop does `addr not in call_ref_sources` on every
call instruction; with a list this is O(n) per call and quadratic
for hot targets (popular runtime stubs can accumulate many sources).
With a set, add/discard/membership are O(1). The only order-sensitive
read was the single-element branch in `__str__`, which now uses
`next(iter(...))`. No external code depends on ordering — only `len`
and truthiness (verified across src/ and tests/).
Validation:
- `make lint` (ruff check + format check) clean.
- `pytest tests/test*` 90 passed, 43 subtests passed.
- pic_hash / opc_hash / serialized report sha256 unchanged on asprox.1 parent 7c3deae commit ab0a332
3 files changed
Lines changed: 19 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
13 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
| |||
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
64 | | - | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
72 | | - | |
| 78 | + | |
73 | 79 | | |
74 | 80 | | |
75 | 81 | | |
| |||
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | | - | |
82 | | - | |
| 87 | + | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
87 | | - | |
88 | | - | |
| 92 | + | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
| |||
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
| |||
0 commit comments