perf(window): remove forced layoutSubtreeIfNeeded + display in viewWillAppear#1030
Closed
perf(window): remove forced layoutSubtreeIfNeeded + display in viewWillAppear#1030
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Time Profiler captured during connect-from-dock-menu (cold launch) showed a 1.71s spike with 1.36s on the main thread, where 388ms (22.7%) lived inside
NSDisplayCycleObserverInvokedriving a recursive_layoutSubtreeWithOldSizecascade through SwiftUI'sSizeFittingLayoutComputerandNSAttributedString.MetricsCache.metrics.The cascade is amplified by two synchronous calls in
MainSplitViewController.viewWillAppear:These were added in PR #1000 (sidebar refactor), likely to prevent a brief unrendered-sidebar flash. But they:
_layoutSubtreeWithOldSizerecursion through every NSHostingController in the sidebar's SwiftUI tree, each evaluatingbodyand negotiating intrinsic sizes via SwiftUI'sLayoutEngineBox.sizeThatFits(which itself measures attributed strings viaTKerningEngine)Recursive cascade visible in the trace:
Fix
Remove the two forced calls. AppKit handles layout and display naturally as part of the window's display cycle — no manual flush needed, and the natural cycle batches related layout passes instead of forcing one-at-a-time.
if let currentSession, let coordinator = sessionState?.coordinator { sidebarContainer.updateSidebarState(...) } - sidebarContainer.view.layoutSubtreeIfNeeded() - sidebarContainer.view.display() - installObservers()Test plan