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() and GsonBuilder().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
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:
Current State
Common problematic patterns in our Kotlin codebase:
Gson()created per file readGson()created per IDE ↔ Core communicationGson()created per React ↔ Kotlin message exchangeGson()created for each save/load operationProposed Solution
Implement
JsonServiceas an IntelliJ Light Service following platform best practices:@Service(Service.Level.APP)annotationGson()andGsonBuilder().create()calls to use the singletonImplementation Location:
extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/services/JsonService.ktExpected Benefits
References
Implementation Plan
I'm willing to implement this optimization and will submit a PR after this issue is reviewed. The implementation will:
Labels: performance, enhancement, intellij
Priority: Medium-High