Skip to content

cmake: Align the Baseline interpreter's labels to 32 bytes with GCC - #1815

Draft
chfast wants to merge 1 commit into
masterfrom
baseline/gcc-align-labels
Draft

chfast wants to merge 1 commit into
masterfrom
baseline/gcc-align-labels

Conversation

@chfast

@chfast chfast commented Nov 16, 2026

Copy link
Copy Markdown
Member

GCC does not align the targets of the computed gotos in the Baseline dispatch loop: -falign-jumps does not apply to them and -falign-labels is off by default. Only 9 of the 155 instruction implementations start at a 16-byte boundary. Each starts where the code before it ends, so any code size change moves the others and changes how the dispatch jumps are predicted.

Build baseline_execution.cpp with -falign-labels=32 with GCC. This aligns every label in the file, so its code grows: the computed-goto loop from 29 KB to 49 KB and libevmone from 181 KB to 237 KB (GCC 16, x86-64-v3).

clang aligns most of the instruction implementations to 16 bytes as loop headers. Aligning them to 32 bytes helped clang at x86-64-v2 and made the jump-heavy benchmarks slower at x86-64-v3, so clang keeps its default.

GCC does not align the targets of the computed gotos in the Baseline
dispatch loop: -falign-jumps does not apply to them and -falign-labels
is off by default. Only 9 of the 155 instruction implementations start
at a 16-byte boundary. Each starts where the code before it ends, so
any code size change moves the others and changes how the dispatch
jumps are predicted.

Build baseline_execution.cpp with -falign-labels=32 with GCC. This
aligns every label in the file, so its code grows: the computed-goto
loop from 29 KB to 49 KB and libevmone from 181 KB to 237 KB (GCC 16,
x86-64-v3).

clang aligns most of the instruction implementations to 16 bytes as
loop headers. Aligning them to 32 bytes helped clang at x86-64-v2 and
made the jump-heavy benchmarks slower at x86-64-v3, so clang keeps its
default.
@chfast

chfast commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Benchmarks

Layout samples: the SMOD handler padded by 0, 4, 8 and 12 bytes, which moves the instructions after it. 17 programs: the evm-benchmarks main and micro programs and 3 MUL contracts (chained through the second stack item, through the top item, independent). Each variant timed in one process, minimum of 9 rounds. Change vs master is the mean over the 4 paddings, [the spread over the paddings: master → this PR].

GCC 14 on GitHub runners, 18 jobs, x86-64-v2 and v3:

CPU jobs geomean (17 programs) JUMPDEST_n0 loop_with_many_jumpdests chained MUL
Xeon 6975P-C, v2 6 −0.1 … +0.1% ±0.1% [≤ 0.4% → ≤ 0.6%] ±0.1% 0.0 … +0.3%
EPYC 7763, v2 2 −1.0%, −0.3% 0.0%; +17.5% [147% → 0.1%] +1.1% [140% → 141%]; −0.7% −16.4%, −16.4%
EPYC 9V74, v2 1 −1.0% 0.0% −3.6% [11% → 27%] −14.5%
Xeon 6975P-C, v3 4 −0.4 … −0.5% −3.4 … −3.5% [7.3–7.8% → 0.1–0.7%] −3.4 … −3.6% [7.6–7.8% → 0.1–0.3%] −0.4 … −1.1%
Xeon 8573C, v3 1 −2.6% −20.0% [49.9% → 0.1%] −19.8% [49.7% → 0.1%] −0.3%
EPYC 7763, v3 2 −8.0%, −0.8% −9.1% [19.9% → 0.0%]; +5.0% [194% → 0.1%] −49.1% [24% → 138%]; −14.7% [199% → 141%] +1.6%, +1.5%
EPYC 9V74, v3 1 −2.7% −20.8% [52.2% → 0.6%] −23.1% [75.9% → 8.8%] −0.3%
EPYC 9V45, v3 1 −0.4% −0.1% −0.2% −1.3%
  • The other programs move by −1.4 … +1.0% (medians over the jobs), except single jobs of structarray_alloc (+3.0%) and signextend (+8.7%, EPYC 9V74 v2).
  • On a Ryzen 9 5950X (Zen 3) with GCC 16 at v3, master runs chained MUL with 6.4M indirect branch mispredictions per run at all 4 paddings, this PR with 0.46M: −32%.
  • -falign-labels=16 left the jump-heavy spread at 7–35% on the runners; =64 measured like =32 with more code.
  • clang 18 with -mllvm -align-all-nofallthru-blocks=5 (32 bytes): the jump-heavy programs −20% at v2 (spread 49–57% → ≤ 2%), but +25% at v3 (its default is fast and stable there).

@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 0.89%

2 warnings

⚠️ 20 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 20 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 5 improved benchmarks
❌ 15 regressed benchmarks
✅ 879 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ baseline/execute/main/swap_math/insufficient_liquidity 31.3 µs 32 µs -2.45%
❌ test_block_context_ops[fork_Osaka-blockchain_test-opcode_GASLIMIT-benchmark-gas-value_1M] 14.1 ms 14.5 ms -2.35%
❌ test_block_context_ops[fork_Osaka-blockchain_test-opcode_PREVRANDAO-benchmark-gas-value_1M] 16.9 ms 17.3 ms -2.22%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP16-benchmark-gas-value_1M] 9.3 ms 9.6 ms -2.18%
❌ baseline/execute/main/swap_math/spent 36.5 µs 37.3 µs -2.12%
❌ baseline/analyse/main/structarray_alloc 5.2 µs 5.3 µs -2.04%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP11-benchmark-gas-value_1M] 9.4 ms 9.6 ms -2.01%
❌ baseline/execute/main/swap_math/received 41.3 µs 42 µs -1.63%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP14-benchmark-gas-value_1M] 9.4 ms 9.5 ms -1.4%
❌ test_block_context_ops[fork_Osaka-blockchain_test-opcode_NUMBER-benchmark-gas-value_1M] 14.1 ms 14.3 ms -1.34%
❌ test_push[fork_Osaka-blockchain_test-opcode_PUSH1-benchmark-gas-value_1M] 9.6 ms 9.7 ms -1.32%
❌ test_block_context_ops[fork_Osaka-blockchain_test-opcode_TIMESTAMP-benchmark-gas-value_1M] 13.5 ms 13.7 ms -1.24%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP13-benchmark-gas-value_1M] 9.3 ms 9.4 ms -1.12%
❌ test_mod[fork_Osaka-blockchain_test-opcode_MOD-mod_bits_63-benchmark-gas-value_1M] 27.2 ms 27.5 ms -1.12%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP10-benchmark-gas-value_1M] 9.3 ms 9.4 ms -1.05%
⚡ test_push[fork_Osaka-blockchain_test-opcode_PUSH0-benchmark-gas-value_1M] 13 ms 12.7 ms +1.83%
⚡ test_msize[fork_Osaka-blockchain_test-mem_size_0-benchmark-gas-value_1M] 13.4 ms 13.2 ms +1.57%
⚡ baseline/analyse/main/sha1_shifts 11 µs 10.9 µs +1.55%
⚡ test_dup[fork_Osaka-blockchain_test-opcode_DUP1-benchmark-gas-value_1M] 9.5 ms 9.4 ms +1.52%
⚡ test_msize[fork_Osaka-blockchain_test-mem_size_1-benchmark-gas-value_1M] 13.4 ms 13.2 ms +1.47%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing baseline/gcc-align-labels (3dbb9db) with master (ba92871)

Open in CodSpeed

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (ba92871) to head (3dbb9db).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1815   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files         186      186           
  Lines       17192    17192           
  Branches     3963     3963           
=======================================
  Hits        16888    16888           
  Misses        235      235           
  Partials       69       69           
Flag Coverage Δ
eest-develop-gmp 26.75% <ø> (ø)
eest-legacy 17.21% <ø> (ø)
eest-libsecp256k1 28.72% <ø> (ø)
eest-stable 83.74% <ø> (ø)
evmone-unittests 93.94% <ø> (ø)
riscv64 94.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 96.60% <ø> (ø)
tooling 94.87% <ø> (ø)
tests 99.80% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant