Repository navigation
Speed up CMake Tools activation: lazy language-service data and no activation-time kit-prune storm - #5035
Merged
Hannia Valera (hanniavalera) merged 6 commits intoSep 9, 2026
Conversation
…ivation Activation previously awaited LanguageServiceData.create(), which serially read and JSON-parsed the four bundled language-service asset files (commands, variables, modules, policies) before providers were registered. On slow or handle-starved machines this delayed activation and could keep the CMake view hidden. LanguageServiceData.create() is now synchronous and returns an unloaded instance. The asset data is loaded on the first hover/completion request via a memoized ensureLoaded() promise shared by concurrent requests; a load failure is memoized as false (never a rejected promise and never cleared) so providers stop returning results without re-reading the four files on every request. provideHover and provideCompletionItems are now async and check the disposed flag and cancellation both before and after awaiting the load. A per-instance disposed flag suppresses late results from a disposed instance. ExtensionManager.enableLanguageServices() now constructs the provider and registers the hover, completion, and language configuration immediately without any asset I/O, storing the instance so disposeLanguageServices() can dispose it, dispose and clear the registration list, and clear the field. enableLanguageServices() also disposes any prior registrations first as a duplicate-registration guard. The one-time localized initialization-failure message is reported via a one-shot callback passed into create().
Hannia Valera (hanniavalera)
force-pushed
the
dev/hanniavalera/activation-backend-perf
branch
from
August 11, 2026 15:54
94b3031 to
4d19175
Compare
readUserKits() previously fire-and-forgot a full pass over every user kit that probed each compiler for existence. This ran on every activation and on every user-kit file reread, launching an unbounded burst of fs.exists()/paths.which() calls. Both helpers collapse all errors to 'not found', so under file-handle exhaustion (EMFILE) valid compilers were misclassified as missing and the user could be prompted to remove valid kits -- while the burst itself added to the handle pressure.
Activation-time pruning is removed: readUserKits() now only reads and updates the in-memory user kit list. Stale-kit detection is preserved via scanForKits(), which still runs the prune after writing scan results, so stale kits are flagged during an explicit kit/compiler scan instead of on every activation.
The prune itself (still used by scan) is hardened: a static single-flight promise prevents overlapping scans from stacking probe bursts; compiler paths are probed sequentially and deduped within a run; and existence is now tri-state ('present' | 'absent' | 'unknown'). Absolute paths are stat'd directly and relative names are resolved with the 'which' package directly (not paths.which), preserving the error cause. Only ENOENT/ENOTDIR count as definitively absent; any other error (EMFILE/ENFILE/EACCES/EPERM/...) is 'unknown' and the kit is skipped, so transient failures never prompt a removal. Prompts are presented sequentially. The tri-state classifier lives in a small dependency-free module (src/kits/compilerPathState.ts) so it can be unit-tested directly.
Hannia Valera (hanniavalera)
force-pushed
the
dev/hanniavalera/activation-backend-perf
branch
from
August 11, 2026 15:54
4d19175 to
ab0ca6b
Compare
Garrett Campbell (gcampbell-msft)
previously approved these changes
Aug 12, 2026
Hannia Valera (hanniavalera)
enabled auto-merge (squash)
September 9, 2026 16:36
Updated the CHANGELOG with recent bug fixes and improvements.
…entries at their section bottoms
Omotola
approved these changes
Sep 9, 2026
Omotola
left a comment
Contributor
There was a problem hiding this comment.
Non-blocking, but: if the first hover/completion triggers the lazy load and it fails (e.g. under the file-handle exhaustion this PR targets), the failure is cached permanently and language services stay off until reload. Might be worth retrying on the next hover instead of caching the failure.
Hannia Valera (hanniavalera)
deleted the
dev/hanniavalera/activation-backend-perf
branch
September 9, 2026 17:20
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.
What
Two backend changes so extension activation no longer blocks on work that isn't needed to activate, and so CMake Tools stops adding to (and misreading) filesystem/handle pressure during startup:
Why
On machines where process/file I/O is intermittently slow (aggressive antivirus scanning of spawned executables, or extension-host file-handle exhaustion /
EMFILE), activation could take minutes and the CMake sidebar stayed hidden. Investigation showed the extreme latency is environmentally triggered, but the extension puts avoidable, environment-sensitive work on the activation critical path, and even contributes to the handle pressure itself:ExtensionManager.init()awaitedenableLanguageServices()first, which serially read and parsed ~594 KB of bundled hover/completion JSON (commands/variables/modules/policies) and registered the providers only after that load. That data is only needed when the user hovers or completes in a CMake file — never for activation, the sidebar, or configure/build.EMFILE/EACCESthe extension both added handle pressure and could prompt to remove valid kits.How
Language-service data (commit 1):
LanguageServiceData.create()is now synchronous; the data loads lazily on the first hover/completion via a memoizedensureLoaded()(a failed load is memoized so it doesn't retry the four files on every keystroke).provideHover/provideCompletionItemsare async and honor cancellation/disposal before and after the load. The four reads stay serial (noPromise.all) and there is no background prewarm, so activation performs zero language-asset I/O.enableLanguageServices()registers the hover/completion providers and language configuration immediately;disposeLanguageServices()disposes the provider and clears its registrations. Language-server-only mode is unaffected.Kit pruning (commit 2):
present/absent/unknown): absolute paths usefs.statand treat onlyENOENT/ENOTDIRas absent; relative names go throughwhich, whose failures are treated asunknown(it synthesizesENOENTfor all failures and so cannot prove absence). A transient error can therefore never prompt removal of a valid kit.Scope / follow-ups
This is a backend activation-performance/correctness fix. It does not change the actual configure/build work or its timing. The remaining irreducible cost at activation is subprocess latency (e.g.
cmake -E capabilities, andvcvarsallforcl.exepresets under antivirus); a companion UI change (#5027) shows an "initializing" placeholder so the sidebar appears immediately while that residual work completes: complementary to this PR, not a substitute for it. Further optimizations identified but intentionally deferred: single-spawn CMake interrogation (capabilities-first), in-process compiler lookup for VS-dev-env detection, and caching compiled JSON schema validators.Testing
yarn backendTests(384 passing) - newtest/unit-tests/backend/kitTriState.test.ts(tri-state classification incl.EMFILE/ENFILE/EACCES→unknown andwhich-error→unknown) andtest/unit-tests/backend/languageServiceLazyLoad.test.ts(lazy memoization / failure / disposal semantics).yarn unitTests- 330 passing.tsc+gulp lintclean.