anomalyco / anomalyco/opencode

edit tool: levenshtein allocates full matrix on every call

Open
#47,604 0 comments 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Sep 6, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

levenshtein() in src/tool/edit.ts allocates a full (n+1)×(m+1) matrix on every call. BlockAnchorReplacer calls it per-line during fuzzy matching, so this creates unnecessary GC pressure on large files. Also, the per-file locks Map (line 35) never evicts entries — every edited filepath stays in memory forever, which is a slow memory leak in long-running sessions.

Plugins

None

OpenCode version

Latest dev branch (337fd144d)

Steps to reproduce

1.Open a long-running opencode session
2.Use the edit tool on many different files (the locks Map grows without bound)
3.For the levenshtein issue: use the edit tool with a fuzzy oldString on a large file — BlockAnchorReplacer runs levenshtein per-line, each allocating a full matrix

Screenshot and/or share link

N/A — this is a code-level perf issue, not a UI bug

Operating System

Linux (Ubuntu)

Terminal

N/A — not terminal-specific

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.