Skip to content

perf(precompile): use malachite for std modexp#3767

Draft
Rjected wants to merge 1 commit into
mainfrom
dan/malachite-modexp
Draft

perf(precompile): use malachite for std modexp#3767
Rjected wants to merge 1 commit into
mainfrom
dan/malachite-modexp

Conversation

@Rjected

@Rjected Rjected commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Switches the default std MODEXP backend from aurora-engine-modexp to malachite::Natural with ModPow::mod_pow. The gmp feature still takes precedence when explicitly enabled, and no-std builds continue to use the existing Aurora implementation.

The Malachite path imports base, exponent, and modulus as big-endian base-256 digits, handles zero modulus the same way as the previous backend, and reduces the base before calling mod_pow because Malachite requires the base to already be reduced modulo the modulus. The new dependency is wired only through revm-precompile/std with default-features = false and naturals_and_integers enabled.

Validated with:

  • cargo check -p revm-precompile
  • cargo check -p revm-precompile --no-default-features
  • cargo test -p revm-precompile modexp
  • cargo test -p revm-precompile modexp --no-default-features
  • cargo check -p revm-precompile --features gmp
  • cargo test -p revm-precompile modexp --features gmp
  • cargo check -p revm-precompile --all-features
  • cargo bench -p revm-precompile --bench bench modexp --no-run
  • cargo fmt --all --check
  • git diff --check

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 62.42%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 4 improved benchmarks
❌ 1 regressed benchmark
✅ 176 untouched benchmarks
⏩ 1 skipped benchmark1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation modexp[marius-1-even] 301.8 µs 353.3 µs -14.6%
Simulation modexp[mod_1024_exp_2] 1,883.8 µs 486.1 µs ×3.9
Simulation modexp[mod_odd_256b_exp_1024] 22 ms 9.3 ms ×2.4
Simulation modexp[mod_even_32b_exp_256] 161.8 µs 124.7 µs +29.77%
Simulation modexp[mod_even_8b_exp_896] 157 µs 141.6 µs +10.83%

Tip

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


Comparing dan/malachite-modexp (b26ead9) with main (84fe60c)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

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