Repository navigation
chore: cherry-pick upstream perf fixes #3539 #3775 #3784 #3823 #3840 - #57
Conversation
(cherry picked from commit fe966f4)
(cherry picked from commit ae95b77) Conflict: `clone_from_alloy` still takes `&AlloyBal` in this fork (upstream bluealloy#3762 changed it to `&[AlloyAccountChanges]` and was not taken). Applied the same preallocated `AddressIndexMap` + insert loop to the fork signature. `try_from_alloy` applied cleanly.
…luealloy#3823) * perf(precompile): use fused multi-miller loop for BLS12-381 pairing Replace the per-pair miller loop and fp12 multiply accumulation in the blst `pairing_check` with a single `blst_miller_loop_n` call, sharing the per-bit fp12 squaring across all pairs. This mirrors the arkworks backend, which already fuses via `multi_pairing`. Uses the raw FFI rather than blst's `miller_loop_n` Rust wrapper, which fans out to a thread pool (undesirable inside a precompile and unavailable on no_std targets), keeping the computation single-threaded and deterministic. The result is bit-identical; only faster. Bench (eip2537, end-to-end precompile): ~6% at 2 pairs, ~21% at 8, ~30% at 16. * fix(precompile): skip infinity pairs in blst KZG pairing check blst_miller_loop_n does not special-case points at infinity, so filter such pairs out before the fused pairing check (e.g. the proof of a constant polynomial is the point at infinity). Add tests for the valid constant-polynomial proof and the invalid mixed-infinity case, and simplify pair collection with unzip/filter. --------- Co-authored-by: rakita <[email protected]> (cherry picked from commit 3cd8b85)
…sage schedule (bluealloy#3840) * perf(precompile): unroll blake2 portable rounds to const-fold the schedule The portable compression function indexed SIGMA with a runtime round index, which cost the const-folding upstream blake2b_simd gets from calling round() with a constant. Per round on aarch64 that meant 16 ldrb loads of the schedule row, 16 message loads at addresses dependent on those bytes, and an r % 10 reciprocal multiply. Take the round index as a const generic and unroll ten physical rounds, using a remaining counter for EIP-152's variable round count. SIGMA has spec period 10, so ten rounds tile any count and re-entering at round 0 is how standard BLAKE2b's rounds 10 and 11 reuse rows 0 and 1. This mirrors what avx2.rs already does. The schedule loads and the modulo disappear from the emitted code, message words stay in registers across rounds, and the loop body drops from 157 to about 120 instructions per round at the cost of a larger function. compress becomes const-eligible as a result. The dispatcher then also looks const-eligible on targets where the cfgs collapse to the portable call alone, but it cannot be, so that lint is allowed with an explanation. * test(precompile): add blake2 compression tests The compression function had no unit tests; it was only covered indirectly through the execution-spec state tests. Add a differential test against a reference implementation written with a runtime round index, over round counts 0..=40 plus larger values, with pseudorandom state, message, counter and final-block inputs. The round counts cover an empty run, a partial tile, the wraparound at ten and a full second tile, which is where an unrolled schedule can go wrong. This calls portable::compress directly rather than the dispatcher, so the portable path is exercised on targets that would otherwise select AVX2. Also add EIP-152 test vector 4 as an oracle independent of both implementations, checked against the portable path and the dispatcher. * perf(precompile): condense unrolled blake2 rounds with a macro Fold the ten copies of the countdown guard and round call into a local rounds! macro; the expansion is identical to the longhand version. Also make compress_portable const now that portable::compress is const, so clippy's missing_const_for_fn stays clean after merging with main. --------- Co-authored-by: rakita <[email protected]> (cherry picked from commit 730fe8f) Conflict: did not take bench-only bluealloy#3848 (`compress_portable` and the portable blake2 benches). The unroll, clippy allow on `compress`, and the compression unit tests applied; `compress_portable` is omitted because this fork has no bench job for it.
Claude review status
🛠️ Review did not finish Attempted head This round did not publish: MODEL_ACTION_FAILED in phase review_retry. Anything listed below is from the last round that did. Re-run the workflow or push a new commit to try again. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…backend (#66) ## Summary Two rules for upstream picks, learned from the first batches (#54, #57) and from how alloy-rs/evm2 backports revm precompile work: - picks are batched by crate or subsystem, one pull request per batch, so one reviewer can read a whole batch; - a pick that touches a precompile is tested under mutually exclusive feature sets (the `std`-only fallback run, the default set, `--all-features`, and the single backend feature it changes), because `--all-features` selects only the preferred backend in each `cfg_if!` block. `REVIEW.md`'s `mega:cherry-pick` row names both. ## API exceptions None (documentation only). ## Test plan The mutually exclusive feature sets were run on `main` at 43485bf for the perf picks in #57: `--no-default-features --features std` (every fallback) 57/57, `std,blst` 57/57, `std,c-kzg` 57/57, the default set 57/57, `--all-features` 57/57. ## Labels checklist `mega:ci`, `api:superset`.
Summary
Cherry-pick five upstream bluealloy/revm performance improvements whose results are unchanged. The fork has no benchmark job; the consumer's instruction-count CI measures the effect.
Suggested title:
chore: cherry-pick upstream perf fixes #3539 #3775 #3784 #3823 #3840Excluded
#3732(perf: avoid reallocations and cloning during commit) is excluded as API-breaking:CacheAccount::newly_createdandCacheAccount::changego from 2 parameters to 1 (semver major onrevm-database), andOnStateHook::on_statechanges from&EvmStateto ownedEvmState. The node's reth implementsOnStateHook, so this breaks a consumer under the patch. Candidate for the next base-line move.Per pick
bluealloy#3539
fe966f4d6421e26af151268526521dc98c4e991a—perf(database): avoid double cloning in take_n_revertsBundleState::take_n_reverts—split_off+mem::replaceinstead ofsplit_atplus twoto_vec.crates/database/src/states/bundle_state.rs.-xtrailer present.bluealloy#3775
ae95b77643504500cc11bfa47bfe6b4ec8e3d768—perf: avoid intermediate BAL account allocationBal::try_from_alloy/clone_from_alloy— preallocatedAddressIndexMapinstead ofcollect::<Vec<_>>()thenfrom_iter.IndexMap::insert.” CodSpeed: “will not alter performance” (181 untouched).crates/state/src/bal/alloy.rs.clone_from_alloystill takes&AlloyBalhere (upstream#3762changed it to&[AlloyAccountChanges]and was not taken). The same insert loop was applied to the fork signature.try_from_alloyapplied cleanly.git patch-id --stablestill matches.-xtrailer present.bluealloy#3784
deca1e64f2999d1ab095376a917c1138354aac05—perf(precompile): reduce bounds checks in precompile parsingchunks_exact+split_at); BN254 arkworks readers take fixed-size arrays.cargo test -p revm-precompile --lib. (A review comment, not the body, posted cargo-asm deltas: pairing 480→415,run_pair313→278, and removal ofslice_index_failon those parsers.)crates/precompile/src/bls12_381/{pairing,g1_msm,g2_msm}.rs,crates/precompile/src/bn254.rs,crates/precompile/src/bn254/arkworks.rs.-xtrailer present.bluealloy#3823
3cd8b85321cf99aba6c66c9a335266624bd43700—perf(precompile): use fused multi-miller loop for BLS12-381 pairingSpeeds up: blst
pairing_check— oneblst_miller_loop_ninstead of per-pair miller + fp12 mul. Infinity pairs are skipped before the fused loop (KZG constant-polynomial proofs).Upstream numbers (PR body): “Bit-identical output … Benchmark via the existing
eip2537pairing bench, end-to-end through the precompile:”Fork paths:
crates/precompile/src/bls12_381/blst.rs,crates/precompile/src/kzg_point_evaluation.rs,crates/precompile/src/kzg_point_evaluation/blst.rs.Fork hook next to it: no.
patch-id: equal.
-xtrailer present.bluealloy#3840
730fe8f8032f0498d044febc6ce59dcdcc185a79—perf(precompile): unroll blake2 portable rounds to const-fold the message scheduleSpeeds up: portable BLAKE2b compression (EIP-152). Round index is a const generic; ten physical rounds tile any count. Loop body
157→120 instructions/round on aarch64.Upstream numbers (PR body): native aarch64, existing
bench/blake2.rs:Fork paths:
crates/precompile/src/blake2/{mod,portable}.rs.Fork hook next to it: no.
Conflict (recorded in the commit body): did not take bench-only
#3848(compress_portableand the portable blake2 benches). The unroll, the clippy allow oncompress, and the compression tests applied.compress_portableis omitted; this fork has no bench job for it. patch-id differs for that reason.patch-id: differs (recorded).
-xtrailer present.API exceptions
none. Public API stays a superset of the PR base. Labels:
mega:cherry-pick,api:superset.Test plan
Results unchanged. Path coverage and what ran:
bundle_state::tests::take_revertscargo nextest run --locked -p revm-databaserevm-statebal::tests::{try_from_alloy_*, clone_from_alloy_*}-p revm-staterevm-precompilebn254::tests::test_bn254_pair, BLS MSM unit tests, pairing input-length errors-p revm-precompilekzg_point_evaluation::tests::{test_constant_polynomial_valid_proof, test_infinity_proof_invalid, test_valid_input, basic_test}plus the crate's pairing path-p revm-precompileblake2::tests::{portable_matches_runtime_index_reference, eip152_vector_4}(portable path, not only the AVX2 dispatcher)-p revm-precompileAlso: workspace nextest (
--locked,--all-features,--no-default-features), clippy, fmt, riscv32/64no_stdcheck, docs, doctest.revm-ee-testsran with the targeted nextest (no precompile-specific fixtures there).scripts/run-tests.shwires the full EEST suite (develop state tests, glamsterdam-devnet state tests, legacy Cancun/Constantinople, blockchain tests). There is no precompile-only filter. Fixtures were not in the worktree; the suite was not downloaded or run here. CIethereum-testsis the gated EEST job.Labels checklist