From 4d4938f9caa542e4edb46bc7390cbb4903df59c7 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 17 Jan 2026 14:26:41 -0800 Subject: [PATCH] Fix performance issue with constantly rebuilding the data model for the sidebar. Fix #4975. --- iOS/SceneCoordinator.swift | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 2bcbd1f12..e88c24e74 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -74,7 +74,7 @@ struct FeedNode: Hashable, Sendable { // Flattened tree structure for the Sidebar private var shadowTable = [(sectionID: String, feedNodes: [FeedNode])]() - private var needsRebuild = false + private var isRebuildingBackingStores = false private(set) var preSearchTimelineFeed: SidebarItem? private var lastSearchString = "" @@ -1606,16 +1606,19 @@ private extension SceneCoordinator { rebuildBackingStores() } - func rebuildBackingStores(initialLoad: Bool = false, updateExpandedNodes: (() -> Void)? = nil, completion: (() -> Void)? = nil) { - Self.logger.debug("SceneCoordinator: rebuildBackingStores: initialLoad \(initialLoad ? "true" : "false")") + static var rebuildCount = 0 - if BatchUpdate.shared.isPerforming { - Self.logger.debug("SceneCoordinator: rebuildBackingStores — skipping because BatchUpdate.shared.isPerforming") - needsRebuild = true + func rebuildBackingStores(initialLoad: Bool = false, updateExpandedNodes: (() -> Void)? = nil, completion: (() -> Void)? = nil) { + Self.logger.debug("SceneCoordinator: rebuildBackingStores: # \(Self.rebuildCount) initialLoad \(initialLoad ? "true" : "false")") + Self.rebuildCount += 1 + + if isRebuildingBackingStores { + Self.logger.debug("SceneCoordinator: rebuildBackingStores — skipping because isRebuildingBackingStores") + queueRebuildBackingStores() return } - BatchUpdate.shared.start() + isRebuildingBackingStores = true addToFilterExceptionsIfNecessary(timelineFeed) treeController.rebuild() treeControllerDelegate.resetFilterExceptions() @@ -1623,14 +1626,8 @@ private extension SceneCoordinator { updateExpandedNodes?() let changes = rebuildShadowTable() mainFeedCollectionViewController.reloadFeeds(initialLoad: initialLoad, changes: changes) { - BatchUpdate.shared.end() completion?() - - if self.needsRebuild { - Self.logger.debug("SceneCoordinator: rebuildBackingStores — self.needsRebuild, so calling rebuildBackingStoresAgain") - self.needsRebuild = false - self.rebuildBackingStores() - } + self.isRebuildingBackingStores = false } }