-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Labels
ide:jetbrainsRelates specifically to JetBrains extensionRelates specifically to JetBrains extensionkind:enhancementIndicates a new feature request, imrovement, or extensionIndicates a new feature request, imrovement, or extension
Description
Description
The IntelliJ plugin currently creates new Gson instances repeatedly throughout the codebase. This pattern is an anti-pattern for heavy objects in IntelliJ plugin development and causes unnecessary performance overhead:
- Memory waste: Each Gson instance requires significant memory allocation due to reflection-based type adapter initialization
- GC pressure: Short-lived Gson objects increase garbage collection frequency
- CPU overhead: Repeated reflection operations on every instantiation
- Against IntelliJ best practices: Heavy objects should follow the Light Service pattern
Current State
Common problematic patterns in our Kotlin codebase:
- Config file parsing:
Gson()created per file read - Message handling:
Gson()created per IDE ↔ Core communication - JCEF bridge:
Gson()created per React ↔ Kotlin message exchange - State persistence:
Gson()created for each save/load operation
Proposed Solution
Implement JsonService as an IntelliJ Light Service following platform best practices:
- Create application-scoped singleton service with
@Service(Service.Level.APP)annotation - Provide two Gson instances:
- Standard compact formatter for production use
- Pretty-printed formatter for debugging and config files
- Add convenience methods for common JSON operations
- Migrate all existing
Gson()andGsonBuilder().create()calls to use the singleton
Implementation Location:
- Service:
extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/JsonService.kt - Pattern: Light Service (zero XML configuration, auto-discovered by platform)
- Scope: Application-level (single instance per IDE session)
- Thread-safety: Gson is inherently thread-safe
Expected Benefits
- Reduced memory footprint: Single initialization instead of repeated allocations
- Lower GC pressure: Fewer short-lived objects
- Better CPU efficiency: Reflection-based initialization done once
- Platform compliance: Follows IntelliJ Platform SDK recommendations for resource-intensive objects
References
Implementation Plan
I'm willing to implement this optimization and will submit a PR after this issue is reviewed. The implementation will:
- Create the JsonService Light Service
- Migrate all existing Gson instantiations
- Ensure no functional regressions (all tests pass)
- Follow Continue's contribution guidelines
Labels: performance, enhancement, intellij
Priority: Medium-High
joffeoja, sayah-y, fares-ben-chaabane, QianKuang8, icanit and 1 more
Metadata
Metadata
Assignees
Labels
ide:jetbrainsRelates specifically to JetBrains extensionRelates specifically to JetBrains extensionkind:enhancementIndicates a new feature request, imrovement, or extensionIndicates a new feature request, imrovement, or extension
Type
Projects
Status
Todo