Skip to content

snapshot.diffFull hangs process and exhausts memory on large generated text files #48616

Description

@OmarAlaaeldein

Description

When working in a repository with large generated text files (e.g. simulation meshes, large logs, or dataset dumps with 50,000+ lines or several megabytes) that are modified, OpenCode's snapshot service freezes the entire process.

Profiling shows single-threaded CPU usage pegged at 100%+ and memory expanding beyond 1.8GB before the TUI/event loop locks up completely.

The root cause is in snapshot.diffFull(): after tracking changes, it loads both the before and after files into memory as strings and runs diff.structuredPatch(). Running Myers diff algorithm in JavaScript on arrays of 50k–1,000k lines consumes O(ND) time/space, starving the event loop.

OpenCode version

1.18.30

Steps to reproduce

  1. In any repository, generate or modify a text file with 50,000+ lines (e.g. a mesh file or large log).
  2. Trigger any tool call or step that causes OpenCode to record a session snapshot.
  3. OpenCode triggers snapshot.diffFull(from, to).
  4. CPU spikes to 100%+ and the process freezes.

Operating System

macOS (darwin-arm64) / Linux

Terminal

Ghostty / any

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions