Skip to content

Conversation

@connor4312
Copy link
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
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

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slowness in MCP server teardown

3 participants