GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(core): speed up diff calculation significantly by natewill · Pull Request #20731 · anomalyco/opencode

Conversation

@natewill

@natewill natewill commented Apr 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #20734
Closes #11486

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR speeds up the Snapshot.diffFull function, somewhat similar to how #20564 and #20551 speed up revert.

Currently, diffFull handles one file at a time when when loading blob contents. This means for n files it's spawning 2n git processes for git show from: and git show to:. Similar to the old revert function, each git process has significant overhead (10-20ms) per process, making the entire function very slow.

This change batches files by using git cat-file --batch to do all of the work for git show in one git command. This reduces the work for git show from 2n to a constant factor of 1, while preserving the existing single-file path as a fallback if the batched operation fails.

On my machine, a Snapshot.diffFull for a 1000 file diffFull went 13.68s to ~0.34s which is a 40x speed up. This function is ran frequently in the application, making this speedup worthwhile.

How did you verify your code works?

  • Ran targeted bun test tests for Snapshot.diffFull(), including:
    • interleaved added / modified / deleted / binary diffs
    • made sure it preserved diff ordering
    • tests on existing baseline diffFull scenarios

All of these passed

Screenshots / recordings

Not a UI change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
natewill added 4 commits April 2, 2026 14:22
@natewill
perf(opencode): batch snapshot diffFull blob reads
f5dbc88
@natewill
refactor(opencode): simplify diffFull batch helper
11400ea
@natewill
refactor(opencode): align snapshot helper formatting
70cf786
@natewill
test(opencode): preserve diffFull order
e9482c2
@github-actions github-actions Bot added the contributor label Apr 2, 2026
@natewill
Merge branch 'dev' into difffull-performance
2d88e54
natewill
natewill commented Apr 2, 2026
View reviewed changes
Comment thread packages/opencode/src/snapshot/index.ts
const diffFull = Effect.fnUntraced(function* (from: string, to: string) {
return yield* locked(
Effect.gen(function* () {
const catFile = Effect.fnUntraced(

@natewill natewill Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can’t use the normal git() helper here because git cat-file --batch needs us to write refs to stdin and read raw stdout bytes back, and the normal helper just treats everything like plain text.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@natewill
natewill marked this pull request as ready for review April 2, 2026 19:04
natewill
natewill commented Apr 2, 2026
View reviewed changes
Comment thread packages/opencode/src/snapshot/index.ts
const out = new Map<string, string>()
const dec = new TextDecoder()
let i = 0
for (const ref of refs) {

@natewill natewill Apr 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each batch entry is either "<ref> missing" for added/deleted files or "<id> blob <byte_size>\n<file_contents>\n".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kitlangton added a commit that referenced this pull request Apr 4, 2026
@kitlangton @natewill
perf(opencode): batch snapshot diffFull blob reads
434511e
Derived from #20731.

Co-authored-by: Nate Williams <[email protected]>
@kitlangton kitlangton mentioned this pull request Apr 4, 2026
perf(opencode): batch snapshot diffFull blob reads #20752
Merged
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@rekram1-node

rekram1-node commented May 15, 2026

Copy link
Copy Markdown
Member

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node rekram1-node closed this May 15, 2026
@rekram1-node rekram1-node added the automated-pr-cleanup label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] diff calculation is slow [PERF] /undo /redo really slow on larger repos and/or long histories

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@natewill @rekram1-node
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.