From 4929e37507b530cb1d0e92cfcd252b0abefb4f2f Mon Sep 17 00:00:00 2001 From: baude Date: Mon, 19 Feb 2018 08:40:43 -0600 Subject: Performance enhancement for podman images Previous code was using slow routines to collect some of the information needed to output images. Specifically size was being calculated instead of using the cached, already known size already available. Also, straight- lined several of the code paths. Overall assessment is that these improvements cut the time for images in half. Signed-off-by: baude Closes: #365 Approved by: mheon --- libpod/runtime_img.go | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) (limited to 'libpod/runtime_img.go') diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index 76687351d..cc6275494 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -108,6 +108,9 @@ type imageDecomposeStruct struct { transport string } +// ImageResultFilter is a mock function for image filtering +type ImageResultFilter func(inspect.ImageResult) bool + func (k *Image) assembleFqName() string { return fmt.Sprintf("%s/%s:%s", k.Registry, k.ImageName, k.Tag) } @@ -1262,3 +1265,178 @@ func getPolicyContext(ctx *types.SystemContext) (*signature.PolicyContext, error } return policyContext, nil } + +// sizer knows its size. +type sizer interface { + Size() (int64, error) +} + +func imageSize(img types.ImageSource) *uint64 { + if s, ok := img.(sizer); ok { + if sum, err := s.Size(); err == nil { + usum := uint64(sum) + return &usum + } + } + return nil +} + +func reposToMap(repotags []string) map[string]string { + // map format is repo -> tag + repos := make(map[string]string) + for _, repo := range repotags { + var repository, tag string + if len(repo) > 0 { + li := strings.LastIndex(repo, ":") + repository = repo[0:li] + tag = repo[li+1:] + } + repos[repository] = tag + } + if len(repos) == 0 { + repos[""] = "