Skip to content

core: compute changeset diffs from metadata instead of full-content g… - #13615

Merged
marcosnils merged 2 commits into
mainfrom
push-lomvoqqtzlzm
Jul 15, 2026
Merged

marcosnils merged 2 commits into
mainfrom
push-lomvoqqtzlzm

Conversation

@marcosnils

Copy link
Copy Markdown
Contributor

…it diffs

Changeset.computePaths, diffStats, and isEmpty ran git diff --no-index over both fully mounted trees, reading every byte of before and after even for a one-file change. On large directories this floods the engine cgroup with gigabytes of page cache and dirty pages per query, showing up as an engine memory spike that can leave the host unresponsive.

Compute the delta with a stat-based double walk instead (fsdiff): files backed by the same inode are unchanged, metadata-suspect files are verified by content comparison, and the new CompareInodeThenContent mode closes the same-size/same-mtime stat collision hole. git still provides rename pairing and numstat, but scoped to materialized copies of only the changed files, making the whole path O(changed files) instead of O(tree). Falls back to the full-tree git diff on any error.

@marcosnils
marcosnils requested a review from sipsma July 12, 2026 04:20
@sipsma

sipsma commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

🤖 This comment was drafted by Codex; Erik has read and approved it.

When rename detection is triggered by any added and removed file, this path also copies every modified file into /tmp, even when withStats=false. A small rename combined with one large modified file can therefore cause enormous temporary writes and dirty-page pressure, partially recreating the resource problem this PR is intended to solve.

Concrete example and control flow

Suppose the changeset contains:

before/large.db       50 GiB
before/old-name.txt   "hello"

after/large.db        50 GiB, modified
after/new-name.txt    "hello"

The delta walk produces:

Modified: large.db
Removed:  old-name.txt
Added:    new-name.txt

The addition and removal set detectRenames=true. At that point, the staging lists are initialized with all modified files:

beforePaths := slices.Clone(modified) // large.db
afterPaths := slices.Clone(modified)  // large.db

The actual rename candidates are then appended. Consequently, the temporary trees contain:

before: large.db, old-name.txt
after:  large.db, new-name.txt

materializeDeltaFiles copies both versions of large.db with io.Copy, producing approximately 100 GiB of temporary writes before Git performs the rename comparison. If large.db is sparse, this can also materialize its holes into real temporary storage.

The modified file cannot participate in rename pairing because it exists at the same path on both sides. For IsEmpty, even the rename comparison is unnecessary: the added/removed files already prove that the changeset is non-empty.

Suggested possible fixes

  1. Only add modified files to the staging lists when materializeModified is true:
var beforePaths, afterPaths []string

if materializeModified {
    beforePaths = slices.Clone(modified)
    afterPaths = slices.Clone(modified)
}

if detectRenames {
    beforePaths = append(beforePaths, delta.removedFiles...)
    afterPaths = append(afterPaths, delta.addedFiles...)
}

This would make ComputePaths stage only the added/removed rename candidates while preserving the current DiffStats behavior.

  1. Give IsEmpty a specialized delta path: return false immediately if any file was added or removed; otherwise verify the modified candidates and return whether that verified list is empty. That would avoid temporary staging and Git entirely for IsEmpty.

marcosnils and others added 2 commits July 13, 2026 15:05
…it diffs

Changeset.computePaths, diffStats, and isEmpty ran `git diff --no-index`
over both fully mounted trees, reading every byte of before and after even
for a one-file change. On large directories this floods the engine cgroup
with gigabytes of page cache and dirty pages per query, showing up as an
engine memory spike that can leave the host unresponsive.

Compute the delta with a stat-based double walk instead (fsdiff): files
backed by the same inode are unchanged, metadata-suspect files are
verified by content comparison, and the new CompareInodeThenContent mode
closes the same-size/same-mtime stat collision hole. git still provides
rename pairing and numstat, but scoped to materialized copies of only the
changed files, making the whole path O(changed files) instead of O(tree).
Falls back to the full-tree git diff on any error.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Marcos Nils <[email protected]>
Rename detection only needs the added/removed candidates, so stage
modified files only when numstat needs their content. Give IsEmpty a
dedicated delta path that never stages files or invokes git: added or
removed files prove non-emptiness, and modified candidates verify with
an early exit.


Signed-off-by: Marcos Nils <[email protected]>
@marcosnils
marcosnils merged commit c5b1aaa into main Jul 15, 2026
87 checks passed
@marcosnils
marcosnils deleted the push-lomvoqqtzlzm branch July 15, 2026 18:49
tiborvass pushed a commit that referenced this pull request Jul 15, 2026
Since #13615 the metadata delta path sorts added/removed/modified paths
while the git-based fallback does not, so the order a caller observes
silently depends on which implementation ran for a given mount. The
fallback's rename expansion also collects paths from map iteration, so
its order was never fully deterministic to begin with.

Sort the fallback's outputs exactly like the delta path and update the
one exact-order expectation in the integration suite; every other path
assertion already uses ElementsMatch/Contains.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
shykes pushed a commit that referenced this pull request Jul 16, 2026
shykes pushed a commit that referenced this pull request Jul 16, 2026
Since #13615 the metadata delta path sorts added/removed/modified paths
while the git-based fallback does not, so the order a caller observes
silently depends on which implementation ran for a given mount. The
fallback's rename expansion also collects paths from map iteration, so
its order was never fully deterministic to begin with.

Sort the fallback's outputs exactly like the delta path and update the
one exact-order expectation in the integration suite; every other path
assertion already uses ElementsMatch/Contains.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
marcosnils added a commit that referenced this pull request Jul 29, 2026
marcosnils pushed a commit to marcosnils/dagger that referenced this pull request Aug 25, 2026
Since dagger#13615 the metadata delta path sorts added/removed/modified paths
while the git-based fallback does not, so the order a caller observes
silently depends on which implementation ran for a given mount. The
fallback's rename expansion also collects paths from map iteration, so
its order was never fully deterministic to begin with.

Sort the fallback's outputs exactly like the delta path and update the
one exact-order expectation in the integration suite; every other path
assertion already uses ElementsMatch/Contains.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
(cherry picked from commit 8de657a)
marcosnils pushed a commit that referenced this pull request Aug 25, 2026
Since #13615 the metadata delta path sorts added/removed/modified paths
while the git-based fallback does not, so the order a caller observes
silently depends on which implementation ran for a given mount. The
fallback's rename expansion also collects paths from map iteration, so
its order was never fully deterministic to begin with.

Sort the fallback's outputs exactly like the delta path and update the
one exact-order expectation in the integration suite; every other path
assertion already uses ElementsMatch/Contains.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
(cherry picked from commit 8de657a)
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.8

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.8 - 2026-07-29

### Changed

- Changeset diffs are now computed from filesystem metadata instead of full-content comparison, significantly speeding up diff computation for large directories. by @marcosnils in
  dagger/dagger#13615

### Fixed

- Dockerfile build layer caching so unrelated build-context changes no longer bust the cache: `COPY`-ed directories now get a content-based cache identity, re-keying downstream steps only when copied content
  actually changes. by @marcosnils in dagger/dagger#13765
- The `--x-release` CLI re-exec so `_EXPERIMENTAL_DAGGER_RUNNER_HOST` is preserved (with a warning) instead of being stripped, and clarified its startup message to avoid implying it runs from any build. by
  @tiborvass in dagger/dagger#13752
- Silent SDK sessions no longer retain frontend telemetry in memory while Cloud and OTLP export remain enabled. `DAGGER_SILENT` is now honored as the equivalent of `--silent`. by @sipsma in
  dagger/dagger#13762

### What to do next?

- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.8">https://github.com/dagger/dagger/releases/tag/v0.21.8</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!15378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants