From 07d3ce2dec3a27edafb2dd573f36de36dae7876d Mon Sep 17 00:00:00 2001 From: George Nachman Date: Thu, 27 Jan 2022 12:41:05 -0800 Subject: [PATCH] Increase the size of the sticker LRU cache. We ship with 49 stickers and the previous cache size of 32 led to thrasing every time a chat was opened. Since sticker packs can be as large as 200 stickers and we hold three pages in cache while the keyboard is open, increase the cache size for the main app to 600. For the share extension, make it 64 to minimize memory use while avoiding threashing. The cost of this cache is just the sticker metadata (unique ID, emoji description, etc.) so it won't make much difference in memory utilization. --- SignalServiceKit/src/Util/ModelReadCache.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Util/ModelReadCache.swift b/SignalServiceKit/src/Util/ModelReadCache.swift index 34133af3b1..f48fab47f2 100644 --- a/SignalServiceKit/src/Util/ModelReadCache.swift +++ b/SignalServiceKit/src/Util/ModelReadCache.swift @@ -909,7 +909,18 @@ public class InstalledStickerCache: NSObject { } private let cache: ModelReadCache - private let adapter = Adapter(cacheName: "InstalledSticker", cacheCountLimit: 32, cacheCountLimitNSE: 8) + private static var cacheCountLimit: Int { + if CurrentAppContext().isMainApp { + // Large enough to hold three pages of max-size stickers. + return 600 + } else { + // Large enough to hold the current default 49 stickers with a little room to grow. + return 64 + } + } + private let adapter = Adapter(cacheName: "InstalledSticker", + cacheCountLimit: InstalledStickerCache.cacheCountLimit, + cacheCountLimitNSE: 8) @objc public override init() {