diff --git a/snow/engine/avalanche/bootstrapper.go b/snow/engine/avalanche/bootstrapper.go index 5646195..cdfb77b 100644 --- a/snow/engine/avalanche/bootstrapper.go +++ b/snow/engine/avalanche/bootstrapper.go @@ -17,7 +17,14 @@ import ( ) const ( - cacheSize = 100000 + // We cache processed vertices where height = c * stripeDistance for c = {1,2,3...} + // This forms a "stripe" of cached DAG vertices at height stripeDistance, 2*stripeDistance, etc. + // This helps to limit the number of repeated DAG traversals performed + // + // With stripeDistance == 2500, average DAG width == 25 and processedCache size == 100,000 + // the graph can have depth up to 10,000,000 and hold every stripe in cache (100,000 / 25 == x / 2,500) + stripeDistance = 2500 + cacheSize = 100000 ) // BootstrapConfig ... @@ -175,6 +182,9 @@ func (b *bootstrapper) process(vtxs ...avalanche.Vertex) error { toProcess.Push(parent) } } + if vtx.Height()%stripeDistance == 0 { + b.processedCache.Put(vtx.ID(), nil) + } b.processedCache.Put(vtx.ID(), nil) } }