perf(sessions): sub-second /chat loading for large session histories#27028
Draft
N1kky-wed wants to merge 10 commits into
Draft
perf(sessions): sub-second /chat loading for large session histories#27028N1kky-wed wants to merge 10 commits into
N1kky-wed wants to merge 10 commits into
Conversation
…x parsing, clarifying comments)
…regex, and clean formatting)
… timestamp fallbacks
…ta lastUpdated for perfect sorting
…d legacy json formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/chatcommand 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:
chatRecordingService.ts: New ultra-fast preview path uses rawfd.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.
sessionUtils.ts: Bulkwc -lacross 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.
utils.ts: Stable secondary sort by startTime when lastUpdated ties, fixinginconsistent 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
/chatand compare load time against main branchNote: Windows fallback path (batch-limited buffer scanning) is implemented
but not benchmarked on hardware — community validation welcome.
Pre-Merge Checklist