Make icon cache eviction less aggressive. Remove memory monitor entirely. Seems to hurt more than it hurts. Never used to have that kind of thing on macOS anyway.

This commit is contained in:
Brent Simmons committed 2026-11-09 21:10:14 -08:00
1 parent 38ff16dfcc
commit a509c7d01f
3 files changed
+5 -38

No files matched your search

-1
View File
@@ -239,7 +239,6 @@ let appName = "NetNewsWire"
ArticleThemesManager.shared.start()
NetworkMonitor.shared.start()
MemoryPressureMonitor.shared.start()
#if !SKIP_APP_GROUP_ACCESS
ExtensionContainersFile.shared.start()
@@ -45,7 +45,7 @@ public enum IconLookup {
nonisolated static private let logger = Logger(subsystem: Logger.nnwSubsystem, category: "IconImageDownloader")
private let iconImages = NSCache<NSString, IconImage>() // url: icon image
private var iconImages = [String: IconImage]() // url: icon image
private var urlsInProgress = Set<String>()
private var requestsToRetry = [String: Request]() // url: request that failed transiently
@@ -64,7 +64,7 @@ public enum IconLookup {
Self.logger.debug("Skipping non-http(s) URL: \(url)")
return .unavailable
}
if let iconImage = iconImages.object(forKey: url as NSString) {
if let iconImage = iconImages[url] {
DownloadedImageCache.shared.imageWasUsed(url, checksForUpdates: true)
return .found(iconImage)
}
@@ -87,11 +87,11 @@ public enum IconLookup {
// MARK: - Notifications
@objc func handleAppDidGoToBackground(_ notification: Notification) {
iconImages.removeAllObjects()
iconImages.removeAll()
}
@objc func handleLowMemory(_ notification: Notification) {
iconImages.removeAllObjects()
iconImages.removeAll()
}
/// Made again even when not in memory, since icons made from the old copy may be cached elsewhere.
@@ -175,7 +175,7 @@ private extension IconImageDownloader {
}
func cacheIconImage(_ iconImage: IconImage, url: String) {
iconImages.setObject(iconImage, forKey: url as NSString)
iconImages[url] = iconImage
NotificationCenter.default.post(name: .iconImageDidBecomeAvailable, object: self, userInfo: [Self.urlKey: url])
}
@@ -1,32 +0,0 @@
//
// MemoryPressureMonitor.swift
// RSCore
//
// Created by Brent Simmons on 3/7/26.
//
#if os(macOS)
import Foundation
import Dispatch
/// Observes GCD memory pressure events on macOS.
/// Posts `.lowMemory` on warn or critical.
public final class MemoryPressureMonitor: Sendable {
public static let shared = MemoryPressureMonitor()
private let source: DispatchSourceMemoryPressure
init() {
source = DispatchSource.makeMemoryPressureSource(eventMask: [.warning, .critical], queue: .main)
source.setEventHandler {
AppNotification.postLowMemory()
}
}
public func start() {
source.activate()
}
}
#endif