Skip to content

chat: fix performance slowdowns when closing/reloading the window#287186

Merged
connor4312 merged 2 commits intomainfrom
connor4312/287174
Jan 13, 2026
Merged

chat: fix performance slowdowns when closing/reloading the window#287186
connor4312 merged 2 commits intomainfrom
connor4312/287174

Conversation

@connor4312
Copy link
Copy Markdown
Member

@connor4312 connor4312 commented Jan 12, 2026

  • _onDidChangeToolsScheduler.isScheduled is checked to avoid thrashing setTimeout when disposing many tools
  • WorkspaceExtensionsManagementService was listening to file change events using a debounce. Debounces have overhead because a new timer is scheduled on every single call. For large amount of file changes (during EH shutdown when schemas for tools are deregistered) this caused a notable slowdown. throttle should be functionally equivalent, cc @sandy081
  • avoid triggering input updates (w/ downstream editor effects) each time the input gets parsed, which happened every time tools got changed
  • big hammer -- don't bother deregistering MCP tools if we're already shutting down

Results:

  • 216ms to shut down EH before making these changes
  • 87ms in the first three bullets
  • 54ms after skipping MCP tool deregistering. (Basically all the overhead there was unregistering the JSON schema for tool inputs.)

Closes #287174

- _onDidChangeToolsScheduler.isScheduled is checked to avoid thrashing
  setTimeout when disposing many tools
- WorkspaceExtensionsManagementService was listening to file change events
  using a debounce. Debounces have overhead because a new timer is
  scheduled on every single call. For large amount of file changes
  (during EH shutdown when schemas for tools are deregistered) this
  caused a notable slowdown. `throttle` should be functionally equivalent.
- avoid triggering input updates (w/ downstream editor effects) each
  time the input gets parsed, which happened every time tool is called
- big hammer -- don't bother deregistering MCP tools each time

Results:

- `216ms` to shut down EH before making these changes
- `87ms` in the first three bullets
- `54ms` after skipping MCP tool deregistering. (Basically all the
   overhead there was unregistering the JSON schema for tool inputs.)
Copilot AI review requested due to automatic review settings January 12, 2026 23:02
@connor4312 connor4312 enabled auto-merge (squash) January 12, 2026 23:02
@vs-code-engineering vs-code-engineering bot added this to the January 2026 milestone Jan 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to fix performance slowdowns when closing or reloading the VS Code window, specifically targeting chat and MCP tool-related overhead during Extension Host shutdown. The changes implement several optimizations to reduce shutdown time from 216ms to 54ms.

Changes:

  • Replaced Event.debounce with Event.throttle for file change handling in workspace extensions management
  • Added shutdown optimization to skip MCP tool cleanup during window close
  • Implemented throttle event utility with comprehensive tests
  • Added equals comparison for parsed chat requests to avoid redundant updates
  • Optimized tool registration scheduler to prevent redundant scheduling

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/vs/base/common/event.ts Adds new Event.throttle utility for rate-limiting event firing
src/vs/base/test/common/event.test.ts Adds comprehensive test coverage for throttle function
src/vs/editor/common/core/ranges/offsetRange.ts Adds static equals method for comparing offset ranges
src/vs/workbench/contrib/chat/common/requestParser/chatParserTypes.ts Adds equals method for comparing parsed chat requests
src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts Uses equals comparison to avoid firing redundant input change events
src/vs/workbench/contrib/chat/browser/tools/languageModelToolsService.ts Checks scheduler state before scheduling to avoid redundant setTimeout calls
src/vs/workbench/services/extensionManagement/common/extensionManagementService.ts Switches from debounce to throttle for file change handling
src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.ts Attempts to skip tool cleanup during shutdown for performance

Comment thread src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.ts Outdated
Comment thread src/vs/base/common/event.ts
…bution.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@connor4312 connor4312 merged commit 2b623fa into main Jan 13, 2026
22 checks passed
@connor4312 connor4312 deleted the connor4312/287174 branch January 13, 2026 02:54
eli-w-king pushed a commit that referenced this pull request Jan 14, 2026
…87186)

- _onDidChangeToolsScheduler.isScheduled is checked to avoid thrashing
  setTimeout when disposing many tools
- WorkspaceExtensionsManagementService was listening to file change events
  using a debounce. Debounces have overhead because a new timer is
  scheduled on every single call. For large amount of file changes
  (during EH shutdown when schemas for tools are deregistered) this
  caused a notable slowdown. `throttle` should be functionally equivalent.
- avoid triggering input updates (w/ downstream editor effects) each
  time the input gets parsed, which happened every time tool is called
- big hammer -- don't bother deregistering MCP tools each time

Results:

- `216ms` to shut down EH before making these changes
- `87ms` in the first three bullets
- `54ms` after skipping MCP tool deregistering. (Basically all the
   overhead there was unregistering the JSON schema for tool inputs.)
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Mar 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slowness in MCP server teardown

3 participants