forked from forks/go-ethereum
During my benchmarks on Holesky, around 10% of all CPU time was spent in
PUSH2
```
ROUTINE ======================== github.com/ethereum/go-ethereum/core/vm.newFrontierInstructionSet.makePush.func1 in github.com/ethereum/go-ethereum/core/vm/instructions.go
16.38s 20.35s (flat, cum) 10.31% of Total
740ms 740ms 976: return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
. . 977: var (
40ms 40ms 978: codeLen = len(scope.Contract.Code)
970ms 970ms 979: start = min(codeLen, int(*pc+1))
200ms 200ms 980: end = min(codeLen, start+pushByteSize)
. . 981: )
670ms 2.39s 982: a := new(uint256.Int).SetBytes(scope.Contract.Code[start:end])
. . 983:
. . 984: // Missing bytes: pushByteSize - len(pushData)
410ms 410ms 985: if missing := pushByteSize - (end - start); missing > 0 {
. . 986: a.Lsh(a, uint(8*missing))
. . 987: }
12.69s 14.94s 988: scope.Stack.push2(*a)
10ms 10ms 989: *pc += size
650ms 650ms 990: return nil, nil
. . 991: }
. . 992:}
```
Which is quite crazy. We have a handwritten encoder for PUSH1 already,
this PR adds one for PUSH2.
PUSH2 is the second most used opcode as shown here:
https://gist.github.com/shemnon/fb9b292a103abb02d98d64df6fbd35c8 since
it is used by solidity quite significantly. Its used ~20 times as much
as PUSH20 and PUSH32.
# Benchmarks
```
BenchmarkPush/makePush-14 94196547 12.27 ns/op 0 B/op 0 allocs/op
BenchmarkPush/push-14 429976924 2.829 ns/op 0 B/op 0 allocs/op
```
---------
Co-authored-by: jwasinger <j-wasinger@hotmail.com>
|
||
|---|---|---|
| .. | ||
| program | ||
| runtime | ||
| testdata | ||
| analysis_eof.go | ||
| analysis_legacy.go | ||
| analysis_legacy_test.go | ||
| common.go | ||
| contract.go | ||
| contracts.go | ||
| contracts_fuzz_test.go | ||
| contracts_test.go | ||
| doc.go | ||
| eips.go | ||
| eof.go | ||
| eof_control_flow.go | ||
| eof_immediates.go | ||
| eof_instructions.go | ||
| eof_test.go | ||
| eof_validation.go | ||
| eof_validation_test.go | ||
| errors.go | ||
| evm.go | ||
| gas.go | ||
| gas_table.go | ||
| gas_table_test.go | ||
| instructions.go | ||
| instructions_test.go | ||
| interface.go | ||
| interpreter.go | ||
| interpreter_test.go | ||
| jump_table.go | ||
| jump_table_export.go | ||
| jump_table_test.go | ||
| memory.go | ||
| memory_table.go | ||
| memory_test.go | ||
| opcodes.go | ||
| operations_acl.go | ||
| operations_verkle.go | ||
| stack.go | ||
| stack_table.go | ||