Files
syft/internal/layer_squashes.go
T
Alex Goodman 1f667ad93a perf: build lower layer squashes only when a scan reads them
The image source provider now reads images with `image.WithLazyLayerSquashes`: the image squash is built during the read, and each lower layer's squash only when something reads it. A squashed scan never does, so it skips a full file tree copy per layer.

- squashed scans: faster, much less memory on images with many layers
- `scan`/`attest` with all-layers or deep-squashed stay eager (an internal ctx flag), since eager squashing overlaps with fetching and indexing and is faster when every layer gets read
- library callers going through `syft.GetSource` get lazy for every scope, since the scope isn't known when the image is read. All-layers is still correct, just slower
- no public API change

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
2026-10-29 22:40:51 -04:00

18 lines
650 B
Go

package internal
import "context"
type eagerLayerSquashesKey struct{}
// WithEagerLayerSquashes has the image source provider build every layer's squashed tree while it reads the
// image, instead of the first time each one is used. Set it when the scan will read lower layers (any scope but
// squashed): eager squashing overlaps with fetching and indexing the layers, so those scans finish sooner.
func WithEagerLayerSquashes(ctx context.Context) context.Context {
return context.WithValue(ctx, eagerLayerSquashesKey{}, true)
}
func EagerLayerSquashes(ctx context.Context) bool {
v, _ := ctx.Value(eagerLayerSquashesKey{}).(bool)
return v
}