# EVMMAX Benchmarks This document summarizes the current performance of the Geth EIP-5843 implementation work. Several implementation variants are benchmarked: * `eip-5843` - Geth implementation matching the EIP spec. Arithmetic implemented in Go. * `little-endian` - Geth implementation of the EIP spec modified to make the EVMMAX value format little-endian. Arithmetic implemented in Go. * `asm384` - implements same spec as little-endian with x86-64 GoAssembly implementation of the arithmetic operations for 321-384bit widths provided from Supranational in 2020. The code currently lacks validation checks that inputs are less than the modulus. Two types of benchmarks are measured: * `arithmetic` - Go benchmarks of the arithmetic against worst-case inputs. * `evm` - standalone executable EVM benchmarks for each operation/value-size configuration. These contain loops which execute `ADDMODX`/`SUBMODX`/`MULMONTX` against a worst-case input. The setup overhead is amortized by many loop iterations in the benchmark body. To measure worst-case memory latency, all benchmarks use inputs from random locations within the largest EVMMAX-addressable memory space for a given value size (`256 * value_size * 8` bytes). ### Benchmarks with EIP Gas Model Labeled **Note**: error bars show the standard deviation in times (5 samples per benchmark). #### MULMONTX ![](https://github.com/jwasinger/evmmax-bench-plot/raw/master/charts/mulmontx_all.png) #### MULMONTX (1-512 bit widths) ![](https://github.com/jwasinger/evmmax-bench-plot/raw/master/charts/mulmontx_low.png) #### ADDMODX ![](https://github.com/jwasinger/evmmax-bench-plot/raw/master/charts/addmodx_all.png) #### SUBMODX ![](https://github.com/jwasinger/evmmax-bench-plot/raw/master/charts/submodx_all.png) #### SETMODX ![](https://github.com/jwasinger/evmmax-bench-plot/raw/master/charts/setmodx_all.png) I have not made significant effort towards improving the performance of the `eip-5843`. It is likely that an improved implementation could achieve performance close to `little-endian` because most of the added overhead from byteswapping big-endian inputs to system-endian (little-endian on most/all machines) can be covered by [hiding it within the memory latency of input loading](https://github.com/ethereum/EIPs/pull/5843#discussion_r1008747987). Although the assembly implementations of the arithmetic operations are lacking input validation checks, the added overhead shouldn't be significant for `MULMONTX`. #### EIP-5843 Gas Model Justification The EIP states that the gas model is based on 25ns/gas as a target rate which is supported by benchmarks of the ecrecover precompile in Geth (running at 24.06 ns/gas): ``` > cd go-ethereum/core/vm && go test -bench=PrecompiledEcrecover cpu: Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz BenchmarkPrecompiledEcrecover/-Gas=3000-4 16236 72176 ns/op 3000 gas/op 41.56 mgas/s 800 B/op 7 allocs/op ``` #### Reproducing the Benchmarks See the readme at https://github.com/jwasinger/evmmax-bench-plot for instructions.