Skip to content

perf(sessions): sub-second /chat loading for large session histories#27028

Draft
N1kky-wed wants to merge 10 commits into
google-gemini:mainfrom
N1kky-wed:main
Draft

perf(sessions): sub-second /chat loading for large session histories#27028
N1kky-wed wants to merge 10 commits into
google-gemini:mainfrom
N1kky-wed:main

Conversation

@N1kky-wed
Copy link
Copy Markdown

@N1kky-wed N1kky-wed commented May 14, 2026

Summary

The /chat command took 25+ seconds to load with large session histories.
This PR reduces load time to 634ms on a real-world benchmark of 59 sessions / 2.3GB of JSONL.

Details

Three compounding bottlenecks eliminated:

  1. chatRecordingService.ts: New ultra-fast preview path uses raw fd.read()
    calls (64KB head + 128KB tail). Core metadata is extracted via regex directly
    on buffers, while the first user message is extracted via line-based JSON parsing
    to robustly handle nested structures — without streaming the full file.

  2. sessionUtils.ts: Bulk wc -l across all files in a single subprocess call
    (batched at 100 files) replaces per-file subprocess calls. Windows fallback uses
    batch-limited (20 concurrent) Node.js buffer scanning to avoid FD exhaustion.

  3. utils.ts: Stable secondary sort by startTime when lastUpdated ties, fixing
    inconsistent session ordering. Filename timestamp used as reliable startTime
    fallback instead of mtime.

Note: The 25.62s benchmark was recorded on a fresh environment. In practice,
load times frequently exceed 60 seconds on warmed systems with large histories.

Related Issues

Fixes #27027

How to Validate

  1. Generate a large session history (30+ sessions with substantial conversation history recommended — the more messages per session, the larger the files and the more pronounced the improvement)
  2. Run /chat and compare load time against main branch
  3. Verify session list ordering is consistent across multiple opens
  4. On Linux: load time should be under 1 second for typical histories

Note: Windows fallback path (batch-limited buffer scanning) is implemented
but not benchmarked on hardware — community validation welcome.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/chat command loading extremely slow with large histories (25s+)

1 participant