anomalyco / anomalyco/opencode
edit tool: levenshtein allocates full matrix on every call
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.