Repository navigation
dagql, core: sync only the leases that changed, and borrow snapshots dependencies hold - #14871
Merged
Merged
Conversation
Every container a chain of with* calls makes copies each part it doesn't change from the container before it, and its owner lease sync attached a lease of its own for each. A chain of n links holding m mounts attached about n*m leases, each a write to the snapshot metadata: about 21,000 for one build of dagger's CLI with dagger.io/go, about 12 per package exec. When a container copies a part from a result it depends on (delegateContainerPart), it records the snapshot the part then holds. While the part still holds that snapshot, its link is marked borrowed, and the owner lease sync and its cleanup skip it; a part written after the copy, as a path writer copies and then writes, holds a snapshot of its own and keeps its lease. The links are still recorded with the result. The result copied from outlives the copy: a result's dependencies are kept while it keeps its value, and its value is dropped only when nothing depends on it, so the original's lease keeps the snapshot as long as the copy needs it. Borrowing isn't persisted: after a restart, imported links attach leases of their own, as before. Signed-off-by: Erik Sipsma <[email protected]>
withMountedDirectory and withMountedFile put their source's snapshot in the mount unchanged, unless they chown it, and the source is a result the container depends on, which owns that snapshot and outlives the container, as for a copied part. Such a mount's link is now borrowed too, while it holds that snapshot: one mount of a directory or file per container link attached a lease of its own, so a package exec built with a handful of mounts attached a lease for each. A chowned mount is a result of its own and keeps its lease. Signed-off-by: Erik Sipsma <[email protected]>
After an evaluation fills parts of a result, the owner lease sync read every part of the result to diff its leases. For a Container that read waits for each of the container's evaluations still running, to see all its parts coherently, while it holds the result's lease sync lock. A container's parts are filled by separate evaluations (its root filesystem, its exec metadata, each mount), so each one's sync waited on the others and re-read all of them: in a per-package Go build of dagger's CLI, 29,000 syncs and seconds of summed waits, and with one file mount per dependency, 65,000. The sync after a part evaluation now reads and reconciles the parts that evaluation filled, and nothing else. They are complete, and every other part keeps the leases and stored links it has, so the read needs no wait. A value that can't be read by part (anything but a Container, a container acquired whole or restored from persistence, a part below the result) is synced whole, as before. Signed-off-by: Erik Sipsma <[email protected]>
A Container's own lazy groups (its root filesystem, a mount, its metadata) run through its PartHost with no task continuation, and their lease sync was still the whole one: it read every part and waited for the container's other running groups. Those are the syncs that dominated a per-package Go build. The PartHost records the parts each such group filled on the attempt's token; the sync after the group now reconciles those parts alone, as after a part task. A body that records no parts fills the whole value and is synced whole. A test runs two of a container's groups through the cache: the root filesystem's group completes, with its lease, while the mount's group is still running. Without this change it waits for the mount's group. Signed-off-by: Erik Sipsma <[email protected]>
A container group's body also copies the delegated parts whose parent part is already final (consumeFinalParentDelegations), so a part can be filled by another group's body than its own. Its own group then finds it consumed and runs no sync. The scoped sync after the body covered only the group's installed outputs, so such a part kept the owner lease it had at publication, now that it is borrowed and needs none, until another whole sync or the result's release. The sweep now notes each part it copies on the body's task (PartTaskToken.AlsoFilled), and the sync after the body reconciles those parts as well. Signed-off-by: Erik Sipsma <[email protected]>
The full lease sync opens none; these came from a profiling build. Signed-off-by: Erik Sipsma <[email protected]>
A result that selects from another, such as a container's rootfs or a directory's subdirectory, holds the same snapshot as the result it depends on, and attached an owner lease of its own for it: a metadata write per selection. Its dependency is kept while the result keeps its value, so the dependency's hold keeps the snapshot. Mark such links borrowed, as a part copied from a dependency is. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
With a dependency's snapshot borrowed from the start, the child in this test no longer took its own lease on the parent's root filesystem, so the sweep had no lease left to remove. The child now starts with a root filesystem of its own; the sweep replaces it with the parent's, borrowed, and removes the child's lease. Signed-off-by: Erik Sipsma <[email protected]>
grouville
self-requested a review
October 27, 2026 06:03
grouville
approved these changes
Oct 27, 2026
golangci-lint's gocyclo limit, and a tagged switch where staticcheck asks for one. No change in behaviour. Signed-off-by: Erik Sipsma <[email protected]>
The rootfs selection depends on the container, which holds the imported snapshot, so it borrows it and attaches no owner lease of its own: two owners, not three, and one lease fewer at close. Borrowed links aren't persisted, so after the restart its imported link attaches a lease again until the results are loaded and their leases synced. Signed-off-by: Erik Sipsma <[email protected]>
The sync-retry case injected a failure into the child's owner attach during a delegated install, to check the install stays retryable. A delegated child's snapshot is its parent's, which the parent holds, so the child now borrows it and its sync attaches nothing: that failure can't happen on this path. The case becomes borrowed-sync and checks that the child's sync makes no owner attach, that its links are borrowed, that the temporary parent hold is released and that the child's pin is released once. The handling of a failed owner attach stays covered by part_acquisition_test.go and part_inline_test.go. Signed-off-by: Erik Sipsma <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A result that holds snapshots keeps an owner lease for each, so a snapshot stays while a result needs it. This PR cuts how much work and waiting that costs.
Sync only the leases of the parts that changed. A Container's parts (its root filesystem, its exec metadata, each mount) are filled by separate evaluations. After each one, the engine synced the result's owner leases by reading every part. That read waited for the container's other evaluations still running, while holding the result's lease sync lock: in a per-package Go build of dagger's CLI, ~29,000 syncs per build, with seconds of summed waiting. The sync after a part evaluation, a native group or a delegation sweep now reads and reconciles only the parts it filled. Anything that can't be read by part is synced whole, as before.
Borrow a snapshot instead of leasing it again. A result whose snapshot one of its dependencies already holds now borrows it: it gets no lease of its own, and none is removed when it goes. The dependency is kept while the result keeps its value, so the dependency's lease keeps the snapshot. That covers:
After a restart, the import attaches each persisted result's own lease before any result is synced, so a dependency holds the snapshot before anything borrows it.
What it changes for users
Faster builds that make many containers and selections. On a cold build of dagger's CLI with dagger/go's per-package build:
No API or behaviour change otherwise.
Numbers
AWS c8gd.4xlarge (arm64, 16 cores), one fresh dev engine per build, 3 interleaved builds per arm, every build compiling the same source tree.
Tests
TestCacheSnapshotOwnerLeaseBorrowsADependencysSnapshot(a result depending on another that holds snapshot X gets no lease of its own for X, and releasing both removes only the other's lease).All run in CI's
test-split/test-packages.