Skip to content

Memoize image digest resolution across a WithImagesResolved call - #899

Merged
glours merged 1 commit into
compose-spec:mainfrom
ndeloof:memoize-image-digest-resolution
Jul 21, 2026
Merged

Memoize image digest resolution across a WithImagesResolved call#899
glours merged 1 commit into
compose-spec:mainfrom
ndeloof:memoize-image-digest-resolution

Conversation

@ndeloof

@ndeloof ndeloof commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #894.

WithImagesResolved uses a singleflight.Group to collapse concurrent resolutions of the same image, but singleflight forgets a key as soon as its call returns. Images resolved sequentially — a pre_start hook or a type: image volume source equal to service.Image, resolved one after another within a single service transform — therefore still hit the resolver twice.

This backs singleflight with a sync.Map memoizing results for the whole call, so each distinct image reference is resolved exactly once whether the repeat lookups are concurrent or sequential. singleflight still guards the concurrent burst before it reaches the cache.

WithImagesResolved deduplicates concurrent resolutions of the same image
via singleflight, but singleflight forgets a key as soon as its call
returns, so images resolved sequentially — a pre_start hook or a
`type: image` volume source equal to service.Image, resolved one after
another within a single service transform — still triggered a duplicate
registry round-trip.

Back singleflight with a sync.Map memoizing results for the whole call so
each distinct image reference is resolved exactly once, whether the
repeat lookups are concurrent or sequential.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@glours
glours merged commit e70e961 into compose-spec:main Jul 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants