Join GitHub today
Reduce sorts done by ListImagesWithOptions #2338
The PR as a whole is intended to address #2328 by reducing the number of sorts, since that was identified as a bottleneck there.
The second commit caches the result of sorting by timestamp, when that is done. It will be effective to the extent that
There are some modest improvements that could be made with more invasive changes. Possibly the biggest improvement would be to sort images (actually the image tags) when they are fetched, rather than when they are used, since the latter will usually outnumber the former by orders of magnitude.
The ListImagesWithOptions API method lets you supply a list of the fields you want for each container, so that you can cut down on the size of the response when you don't care about some fields. But all the fields are calculated, whatever you ask for, which involves a lot of sorting and filtering. This commit makes the procedure calculating the fields _only_ calculate the fields that were actually requested. Some of the calculations depend on the same intermediate results; so, the approach is to lazily calculate and cache intermediate results.
Much of the time, the images returned from the ListImagesWithOptions API are sorted according to timestamp. As a cheap and simple optimisation for this case, when we're constructing a result, cache both the slice of image.Info records and those records sorted by timestamp. This means, for any given request, images that occur in more than one container will be sorted by timestamp only once.