Commit 605b4b6
authored
fix(analyzing-weights): bind weight changes to the correct function via -W (#58)
## What & why
`analyzing-weights`'s `analyze-weight-diff.py` was mis-attributing
weight changes to the wrong functions and silently dropping flags.
The parser identifies each change's function from (1) the git `@@` hunk
header and (2) `fn NAME(...)` lines in the diff context. For Substrate
weight files **both fail**:
- Hunk headers show the enclosing `impl ... WeightInfo` block, never a
`fn`.
- The `fn NAME(...)` signature sits ~5 lines above the first changed
line (`// Minimum execution time` / `Weight::from_parts`), outside the
default 3-line context — so it usually isn't in the diff at all.
With neither available, `current_fn` stops advancing and changes from
several consecutive functions collapse into one bucket;
`parse_weight_block` then keeps only the last value per variable.
**Observed impact** on a full runtime weight regen (moonbeam #3767):
- A `per-y 3.9K → 18.8K (+386.9%)` change was reported against
`pay_one_collator_reward_best`, but it actually belongs to
`delegate_with_auto_compound` (verified in source: `3_861 → 18_800`).
- Reported **50** changed functions / 7 Section-3 flags; the real
numbers are **~1,040** functions / 22 flags.
## Fix
- **Require `git diff -W` (`--function-context`)** so the `fn` signature
is always present in the diff. Documented in both the script docstring
and `SKILL.md` (step 2), with an explanation of why it's needed.
- **Warn loudly** when a bucket merges multiple functions (detected via
>1 `Minimum execution time` line per bucket — the tell-tale of a diff
produced without `-W`) instead of emitting wrong numbers.
## Verification
- Without `-W`: prints the new warning (33 merged buckets on #3767).
- With `-W`: no warning, 1,037 functions, correct per-function
attribution (spot-checked against source).1 parent 9543931 commit 605b4b6
2 files changed
Lines changed: 55 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
39 | 49 | | |
40 | 50 | | |
41 | 51 | | |
| |||
Lines changed: 43 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
5 | 13 | | |
6 | 14 | | |
7 | | - | |
| 15 | + | |
8 | 16 | | |
9 | | - | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | 20 | | |
13 | | - | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
| |||
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
28 | 40 | | |
29 | 41 | | |
30 | 42 | | |
| |||
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
| 54 | + | |
42 | 55 | | |
43 | 56 | | |
44 | 57 | | |
| |||
239 | 252 | | |
240 | 253 | | |
241 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
242 | 282 | | |
243 | 283 | | |
244 | 284 | | |
| |||
0 commit comments