fix: fix listener leaks and redundant file read in autocomplete#11863
Merged
fix: fix listener leaks and redundant file read in autocomplete#11863
Conversation
- statusBar.ts: onDidChangeConfiguration was registered on every setupStatusBar() call, accumulating unbounded listeners on each config change or autocomplete toggle - NextEditWindowManager: 4 event listeners in setupListeners() were not added to this.disposables, surviving dispose() and accumulating across Next Edit toggle cycles - constructPrefixSuffix: accept pre-loaded file contents instead of calling ide.readFile(), eliminating a redundant file read per completion (the caller already has the contents loaded)
Contributor
Docs ReviewNo documentation updates needed for this PR. Reason: These changes are internal implementation fixes (listener leak prevention and redundant file read elimination) that don't affect user-facing behavior, configuration options, or documented APIs. The autocomplete feature works exactly the same from a user's perspective — these are purely stability and performance improvements in the internal codebase. |
Patrick-Erichsen
approved these changes
Mar 26, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Three focused fixes for autocomplete performance — the highest impact-per-line changes from the analysis of stale PR #8364 and related issues.
statusBar.ts:
onDidChangeConfigurationwas registered on everysetupStatusBar()call. SincesetupStatusBaris called on every config change (including autocomplete toggle), listeners accumulated exponentially — each one re-triggeringsetupStatusBar, which added another listener. Guard with aconfigListenerRegisteredflag.NextEditWindowManager.setupListeners(): 4 VS Code event listeners were created without being added to
this.disposables. Thedispose()method iteratesthis.disposablesto clean up, but these listeners weren't in it — so they survived acrossclearInstance()/re-creation cycles when toggling Next Edit.constructPrefixSuffix: Was calling
ide.readFile()internally, but its only caller (HelperVars.init()) already has the file contents loaded 3 lines above. Changed the signature to acceptfileContents: stringdirectly, eliminating one redundant file read per completion request.Related issues
Fixes #3616
Refs #5055
Refs #8364
Test plan
Summary by cubic
Prevents listener leaks when toggling autocomplete and Next Edit, and removes a redundant file read per completion to improve stability and CPU. Fixes #3616 (refs #5055, #8364).
onDidChangeConfigurationonce with a guard to stop exponential listener growth.this.disposablessodispose()cleans them up between toggle cycles.constructInitialPrefixSuffixaccept preloadedfileContents(updatedHelperVars) to remove an extrareadFileper completion.Written for commit 4794082. Summary will update on new commits.