Commit 6f97516
committed
perf(bench): split instantiation from decode/encode kernel measurement
The previous codec benches conflated three costs into one number:
constructor + buffer fill + decode/encode + destructor. CodSpeed runs
each bench body exactly once under Cachegrind, so the per-iteration
construct/destroy cycle was sitting inside the measurement window —
and the variance analysis on a5b8ee6..fa2db51 showed exactly that
mixing was the source of the 18–110% run-to-run spread on
openjpeg encode CT1.RAW, openjpeg decode CT1.j2k, openjphjs encode
CT1.RAW, and libjpeg decode jpeg400jfif (the only four noisy benches
in the suite).
Refactor: hoist new Decoder()/Encoder() + getEncodedBuffer().set() /
getDecodedBuffer().set() / setNearLossless() to module scope, one
instance per fixture (wasm decoders advance internal state on
decode() and can't be reused across multiple bench bodies). Each
bench body is now a single decoder.decode() or encoder.encode() call.
Two new "instantiate+destroy" benches per codec measure the lifecycle
cost in isolation — that's where the noise was hiding and now it
shows up as its own number rather than smearing into the kernel
measurement.
Net effect: the 4 noisy benches should drop to <1% spread (matching
the dispatcher benches which already cache codec instances), and the
lifecycle cost gets its own signal line that catches regressions in
wasm setup paths.
Affected packages: charls, libjpeg-turbo-8bit, openjpeg, openjphjs.
big-endian/little-endian have no decoder class and dicom-codec's
dispatch.bench.js already caches codec instances via runProcess →
initialize → codecConfig.codec, so neither needs the same change.1 parent fa2db51 commit 6f97516
4 files changed
Lines changed: 179 additions & 98 deletions
File tree
- packages
- charls/bench
- libjpeg-turbo-8bit/bench
- openjpeg/bench
- openjphjs/bench
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
21 | 33 | | |
22 | 34 | | |
23 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
24 | 56 | | |
25 | 57 | | |
26 | 58 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
32 | 71 | | |
33 | 72 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 73 | + | |
| 74 | + | |
39 | 75 | | |
40 | 76 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 77 | + | |
| 78 | + | |
46 | 79 | | |
47 | 80 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 81 | + | |
| 82 | + | |
61 | 83 | | |
62 | 84 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| 26 | + | |
| 27 | + | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
24 | 45 | | |
25 | 46 | | |
26 | 47 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
32 | 60 | | |
33 | 61 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 62 | + | |
| 63 | + | |
47 | 64 | | |
48 | 65 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
1 | 11 | | |
2 | 12 | | |
3 | 13 | | |
| |||
18 | 28 | | |
19 | 29 | | |
20 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
21 | 35 | | |
22 | 36 | | |
23 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
24 | 58 | | |
25 | 59 | | |
26 | 60 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
32 | 73 | | |
33 | 74 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 75 | + | |
| 76 | + | |
39 | 77 | | |
40 | 78 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 79 | + | |
| 80 | + | |
46 | 81 | | |
47 | 82 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 83 | + | |
| 84 | + | |
61 | 85 | | |
62 | 86 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
21 | 47 | | |
22 | 48 | | |
23 | 49 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
29 | 62 | | |
30 | 63 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 64 | + | |
| 65 | + | |
36 | 66 | | |
37 | 67 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 68 | + | |
| 69 | + | |
52 | 70 | | |
53 | 71 | | |
0 commit comments