aboutsummaryrefslogtreecommitdiff
path: root/libpod/image/filters.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-08-04 15:55:53 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-08-07 12:14:11 +0200
commit8827100b98d0e8afa6cd7a8d7415cb748948a417 (patch)
treebdad0e581e317fa7a0e52c3efab489d229149e6b /libpod/image/filters.go
parent1ed1e583a06288bb2f3058f7d4dff7650af5f3bd (diff)
downloadpodman-8827100b98d0e8afa6cd7a8d7415cb748948a417.tar.gz
podman-8827100b98d0e8afa6cd7a8d7415cb748948a417.tar.bz2
podman-8827100b98d0e8afa6cd7a8d7415cb748948a417.zip
image list: speed up
Listing images has shown increasing performance penalties with an increasing number of images. Unless `--all` is specified, Podman will filter intermediate images. Determining intermediate images has been done by finding (and comparing!) parent images which is expensive. We had to query the storage many times which turned it into a bottleneck. Instead, create a layer tree and assign one or more images to nodes that match the images' top layer. Determining the children of an image is now exponentially faster as we already know the child images from the layer graph and the images using the same top layer, which may also be considered child images based on their history. On my system with 510 images, a rootful image list drops from 6 secs down to 0.3 secs. Also use the tree to compute parent nodes, and to filter intermediate images for pruning. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/image/filters.go')
-rw-r--r--libpod/image/filters.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/libpod/image/filters.go b/libpod/image/filters.go
index 9738a7d5e..db647954f 100644
--- a/libpod/image/filters.go
+++ b/libpod/image/filters.go
@@ -29,6 +29,26 @@ func CreatedBeforeFilter(createTime time.Time) ResultFilter {
}
}
+// IntermediateFilter returns filter for intermediate images (i.e., images
+// with children and no tags).
+func (ir *Runtime) IntermediateFilter(ctx context.Context, images []*Image) (ResultFilter, error) {
+ tree, err := ir.layerTree()
+ if err != nil {
+ return nil, err
+ }
+ return func(i *Image) bool {
+ if len(i.Names()) > 0 {
+ return true
+ }
+ children, err := tree.children(ctx, i, false)
+ if err != nil {
+ logrus.Error(err.Error())
+ return false
+ }
+ return len(children) == 0
+ }, nil
+}
+
// CreatedAfterFilter allows you to filter on images created after
// the given time.Time
func CreatedAfterFilter(createTime time.Time) ResultFilter {