diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 94d1060cc..d967f1184 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -902,6 +902,16 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn finalizedRoot = shortLog(node.blockPool.finalizedHead.blck.root), cat = "scheduling" + when declared(GC_fullCollect): + # The slots in the beacon node work as frames in a game: we want to make + # sure that we're ready for the next one and don't get stuck in lengthy + # garbage collection tasks when time is of essence in the middle of a slot - + # while this does not guarantee that we'll never collect during a slot, it + # makes sure that all the scratch space we used during slot tasks (logging, + # temporary buffers etc) gets recycled for the next slot that is likely to + # need similar amounts of memory. + GC_fullCollect() + addTimer(nextSlotStart) do (p: pointer): asyncCheck node.onSlotStart(slot, nextSlot)