-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JetBrains Plugin - Performance and Stability Improvements #5200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 6c7a69b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this 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 implements comprehensive performance and stability improvements for the JetBrains plugin, addressing critical issues including webview flickering, thread leaks, UI freezes, and resource management problems. The changes span multiple layers including thread management infrastructure, monitoring tools, configuration, and core plugin components.
Changes:
- Replaced Timer with IntelliJ's Alarm API for better lifecycle management and automatic cleanup
- Implemented bounded thread pools to prevent unbounded thread growth
- Added comprehensive monitoring infrastructure (ThreadMonitor, ScopeRegistry, DisposableTracker)
- Introduced configurable performance settings with debouncing for file events, editor activation, and edits
- Applied extensive VSCode DOM patches to fix webview rendering issues
- Moved blocking EDT operations outside synchronized blocks to prevent deadlocks
- Added proper coroutine scope lifecycle management with SupervisorJob for fault isolation
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| turbo.json | Added jetbrains-host:build task for build system integration |
| package.json | Added jetbrains-host:build npm script |
| ThreadMonitorTest.kt | Tests for thread monitoring functionality and resource cleanup |
| ScopeRegistryTest.kt | Tests for coroutine scope lifecycle tracking |
| DisposableTrackerTest.kt | Tests for disposable resource tracking and cleanup |
| ThreadLeakPreventionTest.kt | Integration tests validating thread leak prevention |
| PerformanceSettingsTest.kt | Tests for performance configuration values |
| ThreadMonitor.kt | New monitoring class for tracking thread count and detecting leaks |
| ScopeRegistry.kt | New registry for tracking active coroutine scopes |
| DisposableTracker.kt | New tracker for monitoring disposable resources |
| PerformanceSettings.kt | Configurable performance settings for debouncing and concurrency |
| WebViewManager.kt | Major refactoring with Alarm API, bounded thread pools, and improved rendering configuration |
| RooToolWindowFactory.kt | Replaced Timer with Alarm, optimized status updates, batched UI operations |
| TerminalInstance.kt | Added monitoring integration, removed SPDX headers |
| WecoderPlugin.kt | Added bounded IO dispatcher and thread monitoring |
| EditorHolder.kt | Implemented debounced event channels for activation and edits |
| EditorAndDocManager.kt | Added debounced file event processing |
| ExtensionSocketServer.kt | Improved client thread cleanup and lifecycle management |
| RPCProtocol.kt | Added semaphore for RPC concurrency control |
| FileRPCProtocolLogger.kt | Added monitoring imports (minimal change) |
| GitCommitMessageAction.kt | Removed SPDX header and kilocode_change marker |
| jetbrains.patch | Extensive VSCode DOM implementation updates for rendering fixes |
| brown-regions-start.md | Changeset documenting the fixes |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge This PR introduces thread leak prevention and performance improvements for the JetBrains plugin. The implementation follows good practices:
Files Reviewed (14 files)
|
| @@ -1,9 +1,6 @@ | |||
| // SPDX-FileCopyrightText: 2025 Weibo, Inc. | |||
| // | |||
| // SPDX-License-Identifier: Apache-2.0 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why this was here, removing it is no issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been removing headers from the files we've modified because LLM models tend to add this header to new files as well.
| // Version tracking for theme injection | ||
| const THEME_VERSION = Date.now(); | ||
|
|
||
| // Enhanced idempotency check - prevent injection if less than 100ms has passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why those cant change within 100ms? Feels a bit random, cant we do actual idempotency somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to prevent flickering when the plugin browser windows it's out of focus.
markijbema
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems sensible, but concurrency stuff is hard to review for correctness; but I assumed you've tested this well enough.
I've asked some questions, but feel free to merge
Context
idea.logcontinuously until the tool window is opened once #5081This PR addresses critical performance and stability issues in the JetBrains plugin, specifically targeting webview flickering and thread management problems that were causing UI freezes and resource leaks. The changes implement a comprehensive solution across multiple phases to prevent thread leaks, improve UI responsiveness, and enhance overall plugin stability.
The main issues addressed:
Implementation
Phase 1: Core Thread Management Improvements
WebViewInstance.kt
Timerwith IntelliJ'sAlarmAPI for better thread management and automatic cleanupSupervisorJobfor fault isolationboundedIODispatcher) to prevent thread explosiondispose()Key changes:
invokeLaterto avoid blockingAlarminstead ofTimerfor proper lifecycle managementPhase 2: Monitoring Infrastructure
New monitoring classes:
ScopeRegistry.kt- Tracks active coroutine scopes and their lifecycleThreadMonitor.kt- Monitors thread count and detects potential leaksDisposableTracker.kt- Tracks disposable resources for leak detectionThese tools provide visibility into resource usage and help identify leaks during development and testing.
Phase 3: Configuration and Tuning
PerformanceSettings.kt
Phase 4: VSCode DOM Patches
deps/patches/vscode/jetbrains.patch
Phase 5: Build System Integration
package.json & turbo.json
jetbrains-host:buildtask for building the JetBrains host componentTesting
Comprehensive test coverage added:
PerformanceSettingsTest.kt- Validates configuration valuesThreadLeakPreventionTest.kt- Integration tests for thread leak preventionScopeRegistryTest.kt- Tests scope lifecycle trackingThreadMonitorTest.kt- Tests thread monitoring functionalityDisposableTrackerTest.kt- Tests resource trackingTradeoffs
How to Test
Testing Webview Stability
Testing Thread Leak Prevention
Testing Resource Cleanup
Testing Under Load
Running Tests
Monitoring During Development
Enable debug logging to see monitoring output:
// In your IDE's log settings, set these to DEBUG level: ai.kilocode.jetbrains.monitoring ai.kilocode.jetbrains.webviewThis will show: