From bd3f16dbbaeca15ff25610ce3710b100045331b8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 6 Jul 2021 21:56:25 +0900 Subject: [PATCH] internal/graphicsdriver/metal: Change the order of GCed buffers As a big buffer is likely reused, we should remove smaller buffers first. Updates #1196 --- internal/graphicsdriver/metal/graphics.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/graphicsdriver/metal/graphics.go b/internal/graphicsdriver/metal/graphics.go index 27f227e3c..fa3f689e7 100644 --- a/internal/graphicsdriver/metal/graphics.go +++ b/internal/graphicsdriver/metal/graphics.go @@ -425,14 +425,14 @@ func (g *Graphics) availableBuffer(length uintptr) mtl.Buffer { } // GC unused buffers. - const maxUnusedBuffers = 20 + const maxUnusedBuffers = 10 if len(g.unusedBuffers) > maxUnusedBuffers { bufs := make([]mtl.Buffer, 0, len(g.unusedBuffers)) for b := range g.unusedBuffers { bufs = append(bufs, b) } sort.Slice(bufs, func(a, b int) bool { - return bufs[a].Length() < bufs[b].Length() + return bufs[a].Length() > bufs[b].Length() }) for _, b := range bufs[maxUnusedBuffers:] { delete(g.unusedBuffers, b)