Skip to content

Fix image size calculation to show unpacked size#991

Open
Bortnyak wants to merge 18 commits intoapple:mainfrom
Bortnyak:fix-image-size
Open

Fix image size calculation to show unpacked size#991
Bortnyak wants to merge 18 commits intoapple:mainfrom
Bortnyak:fix-image-size

Conversation

@Bortnyak
Copy link
Contributor

@Bortnyak Bortnyak commented Dec 24, 2025

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

#709

Previously, container image list -v only showed compressed blob size. Now it shows:
Snapshot size (unpacked) when available
Compressed blob size as fallback when image hasn't been run yet

This better reflects actual storage usage and matches Docker's behavior of showing unpacked size.
Tests use >= comparisons because filesystems allocate space in fixed blocks (4KB on macOS), making exact byte counts unreliable.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

p.s.: if this doesn't match with the maintainers' vision of how image size should be represented, feel free to close this PR :)

@Bortnyak
Copy link
Contributor Author

Hey @dcantah, take a look at this PR please.

@theetherGit
Copy link

@Bortnyak Does this PR fixes #860 too?

@Bortnyak
Copy link
Contributor Author

Bortnyak commented Dec 30, 2025

@Bortnyak Does this PR fixes #860 too?

No, but if the current one will be accepted, then the pr should be tweaked.

@Bortnyak
Copy link
Contributor Author

Hey @jglogan @dcantah
Can someone take a look please?

@jglogan
Copy link
Contributor

jglogan commented Jan 17, 2026

@Bortnyak I'll try to review it next week. Thanks for the reminder, and sorry for the delay!

Could you rebase it PR to resolve the conflicts?

@Bortnyak
Copy link
Contributor Author

Thanks @jglogan.
Done

@jglogan
Copy link
Contributor

jglogan commented Jan 25, 2026

@Bortnyak Sorry, still owe this a review, I haven’t forgotten

@jglogan jglogan self-requested a review January 25, 2026 17:23
Copy link
Contributor

@jglogan jglogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bortnyak I think this looks fine. See my comment about maybe waiting for a common image size func in ClientImage from #862, and extending it for the snapshot size you're doing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the implementation in #862, if that moves into the image client and we merge that, you could use the same logic for the OCI image size, and then you could extend it so it instead returns a struct containing say, ociImageSize and snapshotSize.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to #1098 now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to both of you. I'll wait until #1098 is merged and will use that logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bortnyak you should be good to go now!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jglogan

I've added the change consolidating size retrieval into a single method that returns both ociImageSize and snapshotSize in an ImageSizeInfo struct, following your suggestion.
Check the PR, please.

@jglogan
Copy link
Contributor

jglogan commented Feb 5, 2026

@Bortnyak Sorry to drag this out, I think it'll need one last rebase to address the big change to the ContainerClient type (see #1139).

…iImageSize and snapshotSize in an ImageSizeInfo struct

Signed-off-by: Bortniak Volodymyr <Bortnyak@users.noreply.github.com>
return response.uint64(key: .imageSize)
}

/// Returns both OCI image size and snapshot size for the specified platform.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update this comment follow the docc format style. You can follow how it is done in the getFullImageSize function in this file.

return fs
}

public func getSnapshotSize(platform: Platform) async throws -> UInt64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: function docc updates

return try await self.snapshotStore.get(for: img, platform: platform)
}

public func getSnapshotSize(description: ImageDescription, platform: Platform) async throws -> UInt64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: function docc updates

@saehejkang
Copy link
Contributor

The command-reference docs could slightly be updated to add a note about the updates to the size that is outputted when running container image list.

https://github.com/apple/container/blob/main/docs/command-reference.md#container-image-list-ls:~:text=Image%20Management-,container,-image%20list%20(ls

@saehejkang
Copy link
Contributor

saehejkang commented Feb 15, 2026

Are these the different types of image sizes that can be outputted?

  • Snapshot Size = Unpacked Size = Full Size (which is outputted currently)
  • Compressed Blob Size

I am thinking it might be worthwhile to output both the sizes in the --verbose output just so users can see how they differ.

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.

4 participants

Comments