Skip to content

v0.8.5 perf(session): metadata-only list_sessions path; avoid full JSON parse on every cleanup #337

@Hmbown

Description

@Hmbown

Problem

SessionManager::list_sessions (crates/tui/src/session_manager.rs:306) reads and JSON-parses every session file in ~/.deepseek/sessions/ to build a Vec<SessionMetadata>. cleanup_old_sessions (line 346) calls list_sessions then sorts and prunes — meaning every cleanup pays the full parse cost for files that are about to be deleted anyway.

For a user with hundreds of historical sessions, this lags the startup path and any session-listing UI.

Fix

Add a metadata-only path:

  • Read each session file's first ~4KB only (enough to JSON-parse the header: id, created_at, last_modified, turn_count, model, etc).
  • For cleanup_old_sessions, use the metadata-only path — we don't need full session contents to decide what to delete.
  • Keep the full-parse path for load_session.

Verify against the existing tests (test_list_sessions at line 586) and add one for the metadata-only path.

Acceptance criteria

  • New list_sessions_metadata() returns header-only metadata without full parse.
  • cleanup_old_sessions switches to the metadata path.
  • Existing list_sessions and tests untouched (load + parse semantics preserved for callers that need the full session).
  • Add a benchmark or smoke test demonstrating the speedup with ≥50 fixture sessions.
  • Standard verification gates pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions