Repository navigation
perf(autocomplete): rank table names from a prebuilt index instead of sorting the catalog - #4593
Merged
Merged
Conversation
… sorting the catalog A table slot copied every table into an item, filtered them with NSString searches, scored and fully sorted them, and kept 400. At 100,000 tables that is 70 to 115 ms per request in a release build. The schema provider now builds a folded name index once per table list. A request binary-searches the typed prefix, runs the contains and subsequence passes on the raw keys only when the kept pool could still change, keeps the best rows in a bounded heap ordered as the full sort was, and builds items only for those rows. Names outside printable ASCII take the provider's own matcher, so the order is the same for every name. Empty-prefix suppression now runs before candidates are collected.
datlechin
enabled auto-merge (squash)
November 26, 2026 01:51
# Conflicts: # apple/Packages/TableProCore/Sources/TableProAutocomplete/SQLCompletionProvider.swift # apple/Packages/TableProCore/Tests/TableProAutocompleteTests/SQLCompletionProviderCatalogTests.swift
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
SQLCompletionNameIndex(TableProAutocomplete) folds a catalog's table list once: names, kinds, the lowercased keys back to back, and the rows sorted by key.SQLSchemaProviderbuilds it once per table list and default schema, and drops it on every table-list or namespace write.poolsurvive, in a bounded heap keyed by score then emission position, so the order is the full sort's. Items, with their matched ranges, are built only for the kept rows.setNamespacesnow also drops the cached bare-name table items: a schema's spelling decides which tables a bare name reaches.completionSessionstays@concurrent, and a cancelled request stops at the same early return as a suppressed one. The test catalog keeps bothonTableRead(main) andindexesTables, and its index read callsonTableReadtoo.Left for a follow-up, noted on the issue: narrowing from the previous request's matches,
schema.andresolveAliasfrom the index, the spelling index, cached column items, and dropping the per-itemUUID.Test plan
SQLCompletionNameIndexTests: 25 queries (statement start,FROM,JOIN,INSERT INTO,DROP,CREATE VIEW, a quoted name, mixed case, views, non-ASCII and control-character names) rank identically through the index and through items: labels, kinds, matched ranges, fuzzy penalties and the truncation flag, over 4,509 tables. Plus the prefix range and the early suppression.SQLSchemaProviderNameIndexTests: the index lists whattableCompletionItems()lists, in the same order, and follows a new table list.verify.sh package TableProCore TableProAutocompleteTests: PASS, 526 executed, 526 passed.verify.sh testover the 24 hosted completion suites (SQLSchemaProvider*,CompletionEngine*,SQLCompletionService*,SQLCompletionProvider*, the adapter and ranking suites): PASS, 359 executed, 359 passed.verify.sh build: PASS. iOSbuild-for-testingfor the generic Simulator: TEST BUILD SUCCEEDED.verify.sh linton every changed Swift file: PASS.swift test -c release):s/se/FROM o/FROM ors/se/FROM o/FROM ors/se/selFROM/FROM o/FROM or/FROM xqPersistent bytes in
SQLSchemaProviderafter a 100,000-table load were not measured; the index keeps two bytes per name character and about 26 bytes per row (the name shares its storage with the table list), against oneSQLCompletionItemper table before, which SQL completion no longer builds.Closes #4540