From ea923b77d4f92101fa453b01c5dfab033f13497a Mon Sep 17 00:00:00 2001 From: Seebs Date: Tue, 4 May 2021 14:45:32 -0500 Subject: [PATCH] don't force immediate recalculate of cache on every update When writing things that cause additions to the cache, mark it dirty and flag it for recomputing, but only sometimes actually do the recalculation, currently implying a 10-second window. We still mark the cache dirty, so if a request comes in, we'll get fresh data, but the query will be slowed down because the recomputation will happen then. But that's better than doing thousands of recalculations which are never used... --- cache.go | 2 ++ fragment.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cache.go b/cache.go index b03e4951c..746934c47 100644 --- a/cache.go +++ b/cache.go @@ -262,6 +262,8 @@ func (c *rankCache) invalidate() { // The cache will remain flagged as dirty and will be recalculated if Top is called. // This may cause unexpected memory growth, so record it in metrics for debugging purposes. c.stats.Count(MetricInvalidateCacheSkipped, 1, 1.0) + // Ensure that we're marked as dirty even if we weren't otherwise. + c.dirty = true return } c.stats.Count(MetricInvalidateCache, 1, 1.0) diff --git a/fragment.go b/fragment.go index 7f5990df4..b3a6786be 100644 --- a/fragment.go +++ b/fragment.go @@ -2505,7 +2505,7 @@ func (f *fragment) importPositions(tx Tx, set, clear []uint64, rowSet map[uint64 } if f.CacheType != CacheTypeNone { - f.cache.Recalculate() + f.cache.Invalidate() } return nil } @@ -2804,7 +2804,7 @@ func (f *fragment) unprotectedImportRoaring(ctx context.Context, tx Tx, data []b } // we only set this if we need to update the cache if anyChanged { - f.cache.Recalculate() + f.cache.Invalidate() } span, _ = tracing.StartSpanFromContext(ctx, "importRoaring.incrementOpN")