From 1ae5e022b65492024cb8dbc365be652a7915c25a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 6 Aug 2023 13:27:28 +0900 Subject: [PATCH] internal/atlas: change when to count up usedAsDestinationCount An image has a counter to count how many times an image is used. Before this change, the counter was updated only when an image was moved from a source backend to a destination backend. This seemed not enough, and an image was likely moved to a source backend more often than necessary (#2676). However, there was also an issue that the counter was updated too aggressively and the image was unlikely moved from a destination to a source image (#2586). In order to resolve this dilemma, let's adopt an intermediate way: count up the counter at most once per frame. Updates #2586 Updates #2676 --- internal/atlas/image.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/internal/atlas/image.go b/internal/atlas/image.go index 810d9922b..070b9d736 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -64,9 +64,15 @@ func flushDeferred() { const baseCountToPutOnSourceBackend = 10 func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) error { + // The counter usedAsDestinationCount is updated at most once per frame (#2676). + for i := range imagesUsedAsDestination { + i.usedAsDestinationCount++ + delete(imagesUsedAsDestination, i) + } + for i := range imagesToPutOnSourceBackend { i.usedAsSourceCount++ - if i.usedAsSourceCount >= baseCountToPutOnSourceBackend*(1<= baseCountToPutOnSourceBackend*(1<