Skip to content

Commit cbbaaf0

Browse files
committed
Revert "defer gc during block processing (#3384)"
Deferred GC seemed like a good idea to reduce the amount of work done during block processing, but a side effect of this is that more memory ends up being allocated in certain workloads which in turn causes an overall slowdown, with a long test showing a net performance effect that hovers around 0% and more memory usage. In particular, the troublesome range around 2M sees a 10-15% slowdown and an ugly memory usage spike. Reverting for now - it might be worth revisiting in the future under different memory allocation patters, but as usual, it's better to not do work at all (like in #3444) than to do work faster. This reverts commit 3a00915.
1 parent 9a4fd90 commit cbbaaf0

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

execution_chain/core/executor/process_block.nim

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,21 +280,15 @@ proc processBlock*(
280280
taskpool: Taskpool = nil,
281281
): Result[void, string] =
282282
## Generalised function to processes `blk` for any network.
283+
?vmState.procBlkPreamble(blk, skipValidation, skipReceipts, skipUncles, taskpool)
283284

284-
# Processing a block involves making lots and lots of small memory allocations
285-
# meaning that GC overhead can make up for 15% of processing time in extreme
286-
# cases - since each block is bounded in the amount of memory needed, we can
287-
# run collection once per block instead.
288-
deferGc:
289-
?vmState.procBlkPreamble(blk, skipValidation, skipReceipts, skipUncles, taskpool)
285+
# EIP-3675: no reward for miner in POA/POS
286+
if not vmState.com.proofOfStake(blk.header, vmState.ledger.txFrame):
287+
vmState.calculateReward(blk.header, blk.uncles)
290288

291-
# EIP-3675: no reward for miner in POA/POS
292-
if not vmState.com.proofOfStake(blk.header, vmState.ledger.txFrame):
293-
vmState.calculateReward(blk.header, blk.uncles)
289+
?vmState.procBlkEpilogue(blk, skipValidation, skipReceipts, skipStateRootCheck)
294290

295-
?vmState.procBlkEpilogue(blk, skipValidation, skipReceipts, skipStateRootCheck)
296-
297-
ok()
291+
ok()
298292

299293
# ------------------------------------------------------------------------------
300294
# End

execution_chain/utils/utils.nim

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,3 @@ func weiAmount*(w: Withdrawal): UInt256 =
173173
func isGenesis*(header: Header): bool =
174174
header.number == 0'u64 and
175175
header.parentHash == GENESIS_PARENT_HASH
176-
177-
template deferGc*(body: untyped): untyped =
178-
when declared(GC_disable):
179-
GC_disable()
180-
181-
when declared(GC_enable):
182-
defer:
183-
GC_enable()
184-
# Perform a small allocation which indirectly runs the garbage collector -
185-
# unlike GC_fullCollect, this will use the usual nim heuristic for running
186-
# the cycle colllector (which would be extremely expensive to run on each
187-
# collection)
188-
discard newSeq[int](1)
189-
190-
body

0 commit comments

Comments
 (0)