Skip to content

Defer CodeDiffView editor creation for restored AI conversations#10032

Draft
kevinchevalier wants to merge 1 commit intomasterfrom
oz/lazy-load-restored-code-diffs
Draft

Defer CodeDiffView editor creation for restored AI conversations#10032
kevinchevalier wants to merge 1 commit intomasterfrom
oz/lazy-load-restored-code-diffs

Conversation

@kevinchevalier
Copy link
Copy Markdown
Contributor

@kevinchevalier kevinchevalier commented May 4, 2026

Closes #10073

Description

Defer CodeDiffView editor creation for restored AI conversations to reduce memory pressure on startup.

When restoring conversations, set_candidate_diffs eagerly created full CodeEditorView + InlineDiffView + text buffers for every file in every exchange, even for diffs in a terminal state (Accepted/Rejected/Reverted) that the user never interacts with. This was the dominant allocation source identified in the heap profile for Sentry #7366781652.

Changes

  • CodeDiffView: Added set_candidate_diffs_deferred() that caches lightweight metadata (line counts, file paths) without creating editor views. Editors are materialized lazily via materialize_deferred_diffs() when the user expands a collapsed diff.
  • AIBlock::set_restored_file_edits: Now uses deferred loading when the restored diff state is complete (Accepted/Rejected/Reverted).
  • CodeDiffState::is_complete(): Made public so block.rs can check state before choosing deferred vs eager loading.

Linked Issue

  • APP-4200 (Sentry #7366781652 — excessive memory usage during AI conversation restoration)

Testing

  • Verified compilation with cargo check -p warp
  • Verified cargo fmt passes
  • The change is backward-compatible: live (non-restored) diffs still use the eager path. Deferred diffs materialize on-demand when expanded, so functionality is preserved.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Conversation: https://staging.warp.dev/conversation/7e927e84-be80-47eb-8558-627af6a404a0
Run: https://oz.staging.warp.dev/runs/019df326-8692-77e2-8b63-273180dfa90b
Plans:

This PR was generated with Oz.

When restoring AI conversations on startup, CodeDiffView eagerly created
full CodeEditorView + InlineDiffView + text buffers for every file in
every exchange, even for diffs already in a terminal state (Accepted/
Rejected/Reverted) that the user never interacts with. This was the
dominant source of memory pressure during conversation restoration.

This change introduces deferred loading for restored diffs:

- Added set_candidate_diffs_deferred() that stores FileDiff data and
  caches lightweight metadata (line counts, file paths) without creating
  editor views.
- Modified set_restored_file_edits() in AIBlock to use deferred loading
  when the diff state is complete (Accepted/Rejected/Reverted).
- Editor views are materialized lazily via materialize_deferred_diffs()
  only when the user expands a collapsed diff header.
- The collapsed header continues to display file edit stats (+N/-M) and
  skill/MCP config buttons using cached data.

Co-Authored-By: Oz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defer CodeDiffView editor creation for restored AI conversations

2 participants