From a56e18bb0ca12474a5e0ca953772804e647c4de6 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 6 May 2020 12:01:19 +0200 Subject: [PATCH] collect garbage at end of each slot (#975) --- beacon_chain/beacon_node.nim | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)