Skip to content

perf(autocomplete): size the completion popup before showing it and update rows in place - #4583

Open
datlechin wants to merge 2 commits into
mainfrom
perf/suggestion-popup-sizing
Open

datlechin wants to merge 2 commits into
mainfrom
perf/suggestion-popup-sizing

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • The completion panel is sized from its items in the turn they change: the list's width and height come from the formulas the view already used, and only the preview below the list is measured, in a small sizing host and cached per preview. The Combine receive(on:) hop and the fittingSize read of the whole panel are gone.
  • On first show the panel is sized and placed before orderFront, so it never appears at the last session's size. Placement uses the screen that holds the caret, since a panel not yet on screen can report the screen its last session used.
  • Rows are keyed by what they show (label, detail, and a repeat count) instead of their offset, and CodeSuggestionLabelView is Equatable, so a re-rank moves rows and skips rebuilding a row that only moved. Keyboard scrolling follows the new row ids, and a chosen row is found again by its id after a refresh.
  • The preview highlight cache is cleared whenever the items change, before the panel measures a preview.

Not in this PR: hosting the list in an NSTableView. The issue makes that conditional on SwiftUI still dominating after these two steps, which needs the typing-1900k Time Profiler run to decide.

Test plan

  • New SuggestionPanelSizeTests: the panel has its final size in the turn its items are set, with the panel still hidden, and equal to the hosting view's fittingSize for five item sets; moving onto a row with a preview grows it by the preview and back; row ids follow the entry and stay unique. The first case fails on main, where the size only lands a main-queue turn later.
  • verify.sh test on every Suggestion* suite and TextViewControllerSuggestionsTests: 61 executed, 61 passed (SuggestionControllerPlacementTests skips here without a screen).
  • Local measurement, Debug build, a 200-row list re-ranked 200 times (assign, layout, draw): main-thread CPU per key 7.18 ms before, 6.96 ms after. Sizing on its own costs 0.06 ms computed against 0.07 ms for fittingSize in this harness, so the issue's 99 ms over 420 keys and the SwiftUI share need the typing-1900k re-run on the maintainer's Mac.

Closes #4541

…pdate rows in place

The panel was resized from a Combine sink one main-queue turn after its items
changed, by reading the hosting view's fittingSize, a full SwiftUI layout of the
panel on every key. It is now sized from the items in the same turn, with only
the preview below the list measured, and placed before it is ordered front.

Rows were keyed by their offset, so a re-rank gave every visible row new content
under the same identity. They are keyed by what they show, and the label view
compares equal when it draws the same, so a row a re-rank only moved is kept.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(autocomplete): size the completion popup before showing it and update rows in place

1 participant