go-ethereum/core
Martin HS 057667151b
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run
core/types, trie: reduce allocations in derivesha (#30747)
Alternative to #30746, potential follow-up to #30743 . This PR makes the
stacktrie always copy incoming value buffers, and reuse them internally.

Improvement in #30743:
```
goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/core/types
cpu: 12th Gen Intel(R) Core(TM) i7-1270P
                          │ derivesha.1 │             derivesha.2              │
                          │   sec/op    │    sec/op     vs base                │
DeriveSha200/stack_trie-8   477.8µ ± 2%   430.0µ ± 12%  -10.00% (p=0.000 n=10)

                          │ derivesha.1  │             derivesha.2              │
                          │     B/op     │     B/op      vs base                │
DeriveSha200/stack_trie-8   45.17Ki ± 0%   25.65Ki ± 0%  -43.21% (p=0.000 n=10)

                          │ derivesha.1 │            derivesha.2             │
                          │  allocs/op  │ allocs/op   vs base                │
DeriveSha200/stack_trie-8   1259.0 ± 0%   232.0 ± 0%  -81.57% (p=0.000 n=10)

```
This PR further enhances that: 

```
goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/core/types
cpu: 12th Gen Intel(R) Core(TM) i7-1270P
                          │ derivesha.2  │          derivesha.3           │
                          │    sec/op    │    sec/op     vs base          │
DeriveSha200/stack_trie-8   430.0µ ± 12%   423.6µ ± 13%  ~ (p=0.739 n=10)

                          │  derivesha.2  │             derivesha.3              │
                          │     B/op      │     B/op      vs base                │
DeriveSha200/stack_trie-8   25.654Ki ± 0%   4.960Ki ± 0%  -80.67% (p=0.000 n=10)

                          │ derivesha.2 │            derivesha.3             │
                          │  allocs/op  │ allocs/op   vs base                │
DeriveSha200/stack_trie-8   232.00 ± 0%   37.00 ± 0%  -84.05% (p=0.000 n=10)
```
So the total derivesha-improvement over *both PRS* is: 
```
goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/core/types
cpu: 12th Gen Intel(R) Core(TM) i7-1270P
                          │ derivesha.1 │             derivesha.3              │
                          │   sec/op    │    sec/op     vs base                │
DeriveSha200/stack_trie-8   477.8µ ± 2%   423.6µ ± 13%  -11.33% (p=0.015 n=10)

                          │  derivesha.1  │             derivesha.3              │
                          │     B/op      │     B/op      vs base                │
DeriveSha200/stack_trie-8   45.171Ki ± 0%   4.960Ki ± 0%  -89.02% (p=0.000 n=10)

                          │ derivesha.1  │            derivesha.3             │
                          │  allocs/op   │ allocs/op   vs base                │
DeriveSha200/stack_trie-8   1259.00 ± 0%   37.00 ± 0%  -97.06% (p=0.000 n=10)
```

Since this PR always copies the incoming value, it adds a little bit of
a penalty on the previous insert-benchmark, which copied nothing (always
passed the same empty slice as input) :

```
goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/trie
cpu: 12th Gen Intel(R) Core(TM) i7-1270P
             │ stacktrie.7  │          stacktrie.10          │
             │    sec/op    │    sec/op     vs base          │
Insert100K-8   88.21m ± 34%   92.37m ± 31%  ~ (p=0.280 n=10)

             │ stacktrie.7  │             stacktrie.10             │
             │     B/op     │     B/op      vs base                │
Insert100K-8   3.424Ki ± 3%   4.581Ki ± 3%  +33.80% (p=0.000 n=10)

             │ stacktrie.7 │            stacktrie.10            │
             │  allocs/op  │ allocs/op   vs base                │
Insert100K-8    22.00 ± 5%   26.00 ± 4%  +18.18% (p=0.000 n=10)
```

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-10-01 10:05:49 +02:00
..
filtermaps core/filtermaps: use slices.Sort to remove duplicated elements (#32602) 2025-09-15 10:42:14 +08:00
forkid params: schedule Osaka/BPO1/BPO2 for testnets (#32735) 2025-09-25 18:07:33 +02:00
history core: initialize history pruning in BlockChain (#31636) 2025-04-15 14:32:46 +02:00
overlay core/overlay: copy BaseRoot in TransitionState.Copy (#32613) 2025-09-15 15:26:16 +08:00
rawdb core/rawdb: update comments (#32668) 2025-09-29 14:45:00 +02:00
state core/state: correct expected value in TestMessageCallGas (#32780) 2025-09-30 10:11:09 +08:00
stateless core/stateless: add vmwitnessstats cli flag to report leaf stats + log to console (#32619) 2025-09-17 15:06:39 +02:00
tracing core/tracing: remove unnecessary 'copy' field skip in TestAllHooksCalled (#32622) 2025-09-16 19:58:37 +08:00
txpool core/txpool: remove unused signer field from TxPool (#32787) 2025-09-30 10:07:54 +08:00
types core/types, trie: reduce allocations in derivesha (#30747) 2025-10-01 10:05:49 +02:00
vm core/vm: using testing.B.Loop (#32660) 2025-09-19 17:06:55 -06:00
.gitignore Renamed chain => core 2014-12-04 10:28:02 +01:00
bench_test.go core: using testing.B.Loop (#32662) 2025-09-19 17:06:27 -06:00
block_validator.go core,miner: implement EIP-7934 - RLP Execution Block Size Limit (#31990) 2025-07-09 11:24:44 +02:00
block_validator_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
blockchain.go core: fix fork readiness log (#32623) 2025-09-18 06:28:03 +02:00
blockchain_insert.go metrics: add chain/gas for cumulative gas usage (#32004) 2025-06-12 20:30:54 +08:00
blockchain_reader.go core/rawdb: reduce allocations in rawdb.ReadHeaderNumber (#31913) 2025-07-15 15:48:36 +02:00
blockchain_repair_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
blockchain_sethead_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
blockchain_snapshot_test.go triedb/pathdb, eth: use double-buffer mechanism in pathdb (#30464) 2025-06-22 20:40:54 +08:00
blockchain_test.go core/rawdb: reduce allocations in rawdb.ReadHeaderNumber (#31913) 2025-07-15 15:48:36 +02:00
chain_makers.go core/state: introduce the TransitionState object (verkle transition part 1) (#31634) 2025-08-05 09:34:12 +08:00
chain_makers_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
dao_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
error.go core, params: add limit for max blobs in blob transaction (#32246) 2025-07-21 16:26:24 +02:00
events.go core, eth, ethstats: simplify chain head events (#30601) 2024-10-16 10:32:58 +03:00
evm.go params,core: add max and target value to chain config (#31002) 2025-02-04 15:43:18 +01:00
gaspool.go core, miner: revert block gas counter in case of invalid transaction (#26799) 2023-03-07 05:23:52 -05:00
gen_genesis.go core: go fmt (#29544) 2024-04-16 15:42:16 +03:00
genesis.go all: add bpo1 and bpo2 overrides (#32737) 2025-09-25 10:21:41 +02:00
genesis_alloc.go params: add hoodi testnet definition (#31406) 2025-03-18 12:07:49 +01:00
genesis_test.go triedb/pathdb, eth: use double-buffer mechanism in pathdb (#30464) 2025-06-22 20:40:54 +08:00
headerchain.go core/rawdb: reduce allocations in rawdb.ReadHeaderNumber (#31913) 2025-07-15 15:48:36 +02:00
headerchain_test.go all: nuke total difficulty (#30744) 2025-01-28 18:55:41 +01:00
mkalloc.go accounts, cmd/geth, core: close opened files (#29598) 2024-04-30 15:47:21 +02:00
rlp_test.go core: using testing.B.Loop (#32662) 2025-09-19 17:06:27 -06:00
sender_cacher.go core: use sync.Once for SenderCacher initialization (#31029) 2025-01-16 14:36:45 +01:00
state_prefetcher.go trie, core/state: introduce trie Prefetch for optimizing preload (#32134) 2025-08-20 21:45:27 +08:00
state_processor.go core: improve error context in state processor for Prague EIPs (#32509) 2025-08-28 22:43:45 +08:00
state_processor_test.go params: update tx gas limit cap (#32230) 2025-07-18 13:22:59 +08:00
state_transition.go internal/ethapi: skip tx gas limit check for calls (#32641) 2025-09-19 13:29:17 +02:00
stateless.go cmd/evm: improve block/state test runner (#30633) 2024-12-02 15:18:02 +01:00
txindexer.go core/rawdb: reduce allocations in rawdb.ReadHeaderNumber (#31913) 2025-07-15 15:48:36 +02:00
txindexer_test.go core/rawdb: integrate eradb backend for RPC (#31604) 2025-06-03 10:47:38 +02:00
types.go all: implement flat deposit requests encoding (#30425) 2024-10-09 12:24:58 +02:00
verkle_witness_test.go core/tracing: add code change reason (#32525) 2025-09-02 12:44:47 +02:00