go-ethereum/eth
rayoo 162cd83ee0 eth/fetcher: lazy-allocate unknown slices in TxFetcher.Notify
TxFetcher.Notify is the entry point for every NewPooledTransactionHashes
message: for a well-connected node with dozens of peers it fires
thousands of times per second. On a warm mempool nearly every announced
hash is already known, because some earlier peer already pushed it, so
the "unknown" filter reduces the batch to nothing.

The function still paid `2 * make([]T, 0, len(hashes))` upfront on every
call, wasting ~32B * len(hashes) per slice × 2 slices (common.Hash is
32B, txMetadata is 2B but aligned). At 256-hash announcements that is
10 KiB of allocator pressure per call for nothing to show for it.

Mirror the lazy-allocation pattern applied to scheduleFetches in
2ca74d2ef ("eth/fetcher: lazy-allocate hashes slice in
scheduleFetches"): defer the allocation to the first append, and size
to `len(hashes)-i` so the capacity is right-sized when a late-arriving
fresh hash is the only one we keep.

Benchmark (Apple M4 Pro, 256-hash batch, benchstat of 3 samples):

  scenario      ns/op        B/op           allocs/op
  AllKnown      2670 → 1915  10240 → 0      2 → 0        (-28% / -100% / -100%)
  HalfNew       4873 → 4968  10304 → 10304  3 → 3        (noise)
  AllNew        5932 → 5982  10304 → 10304  3 → 3        (noise)

AllKnown is the steady-state case. HalfNew and AllNew guard against
regressing the cold path; both stay within measurement noise.
2026-05-07 12:26:10 +08:00
..
catalyst eth/catalyst: allow reorging the head block to a parent (#34767) 2026-05-06 09:59:51 +02:00
downloader eth/downloader: use batch index in deliver reconstruct (#34870) 2026-05-05 12:41:22 +02:00
ethconfig trie: group 2^N binary trie nodes in serialization (#34794) 2026-05-01 15:28:19 +02:00
fetcher eth/fetcher: lazy-allocate unknown slices in TxFetcher.Notify 2026-05-07 12:26:10 +08:00
filters eth/filters: return -32602 when exceeding the block range limit (#34647) 2026-04-08 12:57:29 +02:00
gasestimator core: skip tx gas cap after Amsterdam (#34841) 2026-04-28 17:25:16 +02:00
gasprice cmd, core, trie, triedb: split CachingDB into merkle + binary dbs. (#34700) 2026-04-17 08:55:54 +08:00
protocols eth/protocols/eth: stop serving on unavailable responses (#34787) 2026-05-06 15:36:54 +02:00
syncer eth/downloader: keep current syncmode in downloader only (#33157) 2025-12-08 22:49:57 +01:00
tracers eth/tracers: forward V2 state hooks through mux tracer (#34869) 2026-05-04 21:36:26 +02:00
api_admin.go eth: ignore genesis block on importChain (#27956) 2023-08-21 13:32:34 -04:00
api_backend.go cmd, core, trie, triedb: split CachingDB into merkle + binary dbs. (#34700) 2026-04-17 08:55:54 +08:00
api_backend_test.go core/txpool: add eip2681 check for incoming transactions (#32726) 2025-09-25 13:15:12 +02:00
api_debug.go cmd, core, trie, triedb: split CachingDB into merkle + binary dbs. (#34700) 2026-04-17 08:55:54 +08:00
api_debug_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00
api_miner.go miner: refactor the miner, make the pending block on demand (#28623) 2024-03-06 14:45:03 +02:00
backend.go trie: group 2^N binary trie nodes in serialization (#34794) 2026-05-01 15:28:19 +02:00
dropper.go eth: fix panic in randomDuration when min equals max (#33193) 2025-11-19 01:54:53 +08:00
handler.go miner: add OpenTelemetry spans for block building path (#33773) 2026-03-16 19:24:41 +01:00
handler_eth.go eth/protocols/eth, eth/protocols/snap: delayed p2p message decoding (#33835) 2026-02-15 21:21:16 +08:00
handler_eth_test.go eth: implement EIP-7975 (eth/70 - partial block receipt lists) (#33153) 2026-03-30 15:17:37 +02:00
handler_snap.go eth: check snap satelliteness, delegate drop to eth (#22235) 2021-02-02 10:44:36 +02:00
handler_test.go eth: implement EIP-7975 (eth/70 - partial block receipt lists) (#33153) 2026-03-30 15:17:37 +02:00
peer.go eth/protocols/eth: implement eth/69 (#29158) 2025-05-16 17:10:47 +02:00
peerset.go eth: stabilize tx relay peer selection (#31714) 2025-08-28 16:05:54 +02:00
state_accessor.go core/vm: implement stack arena (#33960) 2026-04-28 11:10:44 +02:00
sync.go miner: add OpenTelemetry spans for block building path (#33773) 2026-03-16 19:24:41 +01:00
sync_test.go eth: implement EIP-7975 (eth/70 - partial block receipt lists) (#33153) 2026-03-30 15:17:37 +02:00