perf(window): defer inspector NSHostingController content until first expansion#1031
Merged
perf(window): defer inspector NSHostingController content until first expansion#1031
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
Step 1A of the pure-SwiftUI scene migration (Phase C-2 in the perf refactor plan).
MainSplitViewController.viewDidLoadinstantiates 3 NSHostingControllers (sidebar, detail, inspector) — one SwiftUI rendering root each. Each root negotiates intrinsic sizes viaNSHostingView.SizeConstraints.update(from:)→ViewGraph.sizeThatFits(_:)during the window's first display cycle, contributing to the 1.19s connect-window-open spike captured in the Time Profiler trace.The inspector starts collapsed by default (
UserDefaults.bool(forKey: inspectorPresentedKey)= false), so its SwiftUI body (UnifiedRightPanelViewwith column inspector, query result summary, etc.) is built but never shown — pure waste at launch.Fix
Apple-pattern lazy view-controller content. The inspector's
NSHostingControlleris created with a placeholderColor.clearroot view when collapsed; the heavyUnifiedRightPanelViewbody is materialized viainspectorHosting.rootView = AnyView(buildInspectorView())only on firstshowInspector()call. If the user had inspector expanded last session (inspectorPresentedKey == true), content materializes immediately at launch — same as before.NSHostingController.rootViewis documented as get/set on Apple's docs, so this is the supported swap pattern. SwiftUI re-evaluates the view graph from scratch when the rootView is replaced.This also establishes the lazy-rootView swap pattern that step 1B (toolbar move to SwiftUI) and step 1C (NavigationSplitView replacement) will reuse.
Test plan
inspectorPresentedKey = false(default): main window opens, inspector pane shows nothing collapsed (same UX), Cmd+Option+I expands → content appearsinspectorPresentedKey = true(had inspector open last session): inspector content visible immediately at launch (same as before)Why this is step 1A, not the full refactor
The full migration to pure SwiftUI scenes (
NavigationSplitView+.toolbar+.inspector) replacingMainSplitViewControlleris a multi-week project. Per the planning discussion in this thread, the safer path is incremental: (1A) lazy inspector ← this PR, (1B) toolbar to SwiftUI.toolbar { ToolbarContent }, (1C)NavigationSplitViewshell. Each step compiles, ships, and is independently reversible.