chat: fix performance slowdowns when closing/reloading the window#287186
Merged
connor4312 merged 2 commits intomainfrom Jan 13, 2026
Merged
chat: fix performance slowdowns when closing/reloading the window#287186connor4312 merged 2 commits intomainfrom
connor4312 merged 2 commits intomainfrom
Conversation
- _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.)
Contributor
There was a problem hiding this comment.
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 |
…bution.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
DonJayamanne
approved these changes
Jan 13, 2026
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.)
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.
throttleshould be functionally equivalent, cc @sandy081Results:
216msto shut down EH before making these changes87msin the first three bullets54msafter skipping MCP tool deregistering. (Basically all the overhead there was unregistering the JSON schema for tool inputs.)Closes #287174