Skip to content

Extension crashes and performance issues due to excessive globalState usage for task history #3784

@KJ7LNW

Description

@KJ7LNW

Problem

The current task history persistence mechanism stores all history items directly in VSCode's globalState, which is causing several critical issues:

  1. VSCode Warnings: The extension triggers VSCode warnings about excessive globalState usage:

    WARN [mainThreadStorage] large extension state detected (extensionId: RooVeterinaryInc.roo-cline, global: true): 6173.2822265625kb. Consider to use 'storageUri' or 'globalStorageUri' to store this data on disk instead.
    
  2. Extension Crashes and UI Issues: Users experience various issues that may be related to memory management and globalState limitations:

    • Complete extension crashes or grey/white screens
    • Memory leaks consuming all available RAM
    • Possible globalState race conditions between VS Code instances leading to hangs, crashes, and VS Code instability
  3. Performance Degradation: Even before crashing, the extension suffers from performance issues due to loading and processing large amounts of history data at once.

  4. globalState Thrashing: The current implementation loads and replaces the entire array of task history items in globalState every time a single task is created or modified. This causes:

    • Excessive memory usage as the entire array is loaded into memory
    • Significant performance overhead for each task operation
    • Potential race conditions when multiple operations attempt to modify the array simultaneously
    • Increased risk of data corruption if a write operation is interrupted
    • Unnecessary network/disk I/O as the entire state is serialized and persisted repeatedly
  5. Scale Problem: A busy developer can accumulate tens of thousands of tasks over the course of a year. At this scale, the globalState approach becomes completely unsustainable:

    • The size of the globalState can grow to many megabytes
    • Loading and processing this amount of data becomes increasingly slow
    • The likelihood of crashes and performance issues increases dramatically
    • VSCode's globalState was never designed to handle this volume of data

Possibly Related Issues

Proposed Solution

Implement a file-based storage system for task history:

  1. Store individual history items as JSON files in a directory structure organized by year and month.
  2. Use globalState only for monthly indexes to enable efficient lookups.
  3. Modify the frontend to fetch history data incrementally by month rather than all at once.

This approach will:

  • Eliminate VSCode warnings about excessive globalState usage
  • Prevent extension crashes due to memory limitations
  • Improve performance by loading history data in smaller chunks
  • Avoid race conditions between VS Code instances by using the filesystem for storage
  • Eliminate globalState thrashing by operating on individual files instead of the entire history array
  • Scale efficiently to handle tens of thousands of tasks accumulated over time

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions