Repository navigation
Done
Labels
Description
Problem
While typing about 420 keys in the 1.9M-character file, SwiftUI took 980 ms of main-thread CPU, almost all of it the completion popup (CodeSuggestionLabelView, SuggestionContentView), and SuggestionController.updateWindowSizeFromContent took another 99 ms of main-queue time (Time Profiler, typing-1900k). That is about 2.6 ms per key spent on a list of at most a few hundred short rows, of which about nine are visible.
Cause
- Every key with the popup open re-ranks and assigns a new
itemsarray (apple/Packages/TableProEditor/Sources/TableProEditorKit/CodeSuggestion/Model/SuggestionViewModel.swift:267-274). - A Combine sink on
model.$itemswith.receive(on: DispatchQueue.main)resizes the window on a later main-queue turn (apple/Packages/TableProEditor/Sources/TableProEditorKit/CodeSuggestion/Window/SuggestionController.swift:75-80).updateWindowSizeFromContentreadshostingView.fittingSize, a full SwiftUI layout of the panel, on every change (apple/Packages/TableProEditor/Sources/TableProEditorKit/CodeSuggestion/Window/SuggestionController+Window.swift:62-68). - On first show, the items are set and
showWindowOnParentorders the panel front in the same turn (SuggestionViewModel.swift:174-183,SuggestionController.swift:190), so it is placed with the size the last session left, and the real size lands one turn later. Whether a wrong-size frame reaches the screen depends on whether that turn runs before the Core Animation commit; not measured. - The size does not need a layout pass: the list's width and height are already computed from the items alone (
apple/Packages/TableProEditor/Sources/TableProEditorKit/CodeSuggestion/View/SuggestionContentView.swift:100-117, fixedrowHeightat:12). Only the preview below the list has a content-dependent height. - Rows use
ForEach(Array(model.items.enumerated()), id: \.offset)(SuggestionContentView.swift:52), and the model notes that entries carry no identity (SuggestionViewModel.swift:335). A re-rank gives every visible row new content under the same identity, so SwiftUI rebuilds each row's label and detail text on every key. - The list sits in a
ScrollViewandLazyVStack, not aList, on purpose: a focusable table view made the panel ask to become key (SQL editor lost focus after tying 'se'. #1885,SuggestionContentView.swift:43-47). Any replacement must keep the panel out of focus.
Change
- Compute the panel size from the items when they are assigned: width and list height from the existing formulas, plus the preview's measured height only when the selected item has a preview. Apply it before
orderFront, in the same turn, and drop thereceive(on:)hop and thefittingSizeread. - Give suggestion entries a stable identity (the item's kind plus label, or an id from the provider) and key the
ForEachon it, so a re-rank moves and keeps row views instead of rewriting all of them. - If SwiftUI still dominates after that, host the list in a view-based
NSTableViewthat refuses first responder, with reused cells, which AppKit documents for long reusable lists, and keep the model-driven selection.
Measure
- Re-run
typing-1900k: SwiftUI time under the popup against 980 ms andupdateWindowSizeFromContentagainst 99 ms over about 420 keys. - 120 fps screen capture of 20 popup opens: frames from the key to the popup at its final size and position, and whether a frame at the wrong size appears.
- The
.completioninterval fromInteractionTracer, median of 50 popups, before and after.
Part of the performance plan.
Activity
datlechin commentedon Nov 26, 2026
#4583 sizes the panel from its items in the same turn, before it is ordered front, measures only the preview, and keys rows by what they show with an
Equatablelabel view.Left:
NSTableViewstep. The issue makes it conditional on SwiftUI still dominating, and that needs thetyping-1900kTime Profiler run, which the lanes do not run. In a local Debug harness (a 200-row list re-ranked 200 times, assign, layout and draw) main-thread CPU per key went from 7.18 ms to 6.96 ms, andfittingSizethere cost only 0.07 ms, so most of the per-key cost is the list's own SwiftUI update and drawing..completioninterval were not run here.