Skip to content

fix: fix listener leaks and redundant file read in autocomplete#11863

Merged
RomneyDa merged 1 commit intomainfrom
fix/autocomplete-listener-leaks
Mar 26, 2026
Merged

fix: fix listener leaks and redundant file read in autocomplete#11863
RomneyDa merged 1 commit intomainfrom
fix/autocomplete-listener-leaks

Conversation

@RomneyDa
Copy link
Copy Markdown
Contributor

@RomneyDa RomneyDa commented Mar 26, 2026

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: onDidChangeConfiguration was registered on every setupStatusBar() call. Since setupStatusBar is called on every config change (including autocomplete toggle), listeners accumulated exponentially — each one re-triggering setupStatusBar, which added another listener. Guard with a configListenerRegistered flag.

  • NextEditWindowManager.setupListeners(): 4 VS Code event listeners were created without being added to this.disposables. The dispose() method iterates this.disposables to clean up, but these listeners weren't in it — so they survived across clearInstance()/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 accept fileContents: string directly, eliminating one redundant file read per completion request.

Related issues

Fixes #3616
Refs #5055
Refs #8364

Test plan

  • Autocomplete still works end-to-end
  • Toggle tab autocomplete on/off 20+ times — CPU should stay stable
  • Toggle Next Edit on/off repeatedly — no performance degradation
  • Existing vitest suite passes

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).

  • Bug Fixes
    • Status bar: register onDidChangeConfiguration once with a guard to stop exponential listener growth.
    • Next Edit: add four VS Code event listeners to this.disposables so dispose() cleans them up between toggle cycles.
    • Autocomplete: make constructInitialPrefixSuffix accept preloaded fileContents (updated HelperVars) to remove an extra readFile per completion.

Written for commit 4794082. Summary will update on new commits.

- 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)
@RomneyDa RomneyDa requested a review from a team as a code owner March 26, 2026 00:05
@RomneyDa RomneyDa requested review from Patrick-Erichsen and removed request for a team March 26, 2026 00:05
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 26, 2026
@continue
Copy link
Copy Markdown
Contributor

continue bot commented Mar 26, 2026

Docs Review

No 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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Mar 26, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2026
@RomneyDa RomneyDa merged commit 41b3b65 into main Mar 26, 2026
55 checks passed
@RomneyDa RomneyDa deleted the fix/autocomplete-listener-leaks branch March 26, 2026 04:04
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Mar 26, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The plugin responds slowly if you turn autocomplete on and off more than 10 times in a row

2 participants