Fix performance penalty when sending tars to daemon by optimizing layer size calculation#292
Draft
Fix performance penalty when sending tars to daemon by optimizing layer size calculation#292
Conversation
Author
|
@jabrown85 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
…re known Co-authored-by: jabrown85 <790999+jabrown85@users.noreply.github.com>
Co-authored-by: jabrown85 <790999+jabrown85@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix performance penalty incurred by sending legacy formatted tars to the daemon
Fix performance penalty when sending tars to daemon by optimizing layer size calculation
Aug 7, 2025
Member
|
@jabrown85 Did you manage to test this fix with Docker + Containerd storage performance issue? |
Contributor
|
Sadly, no @jjbustamante. I think we would need to have access to the storage layer APIs to really improve the perf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the performance penalty incurred by sending legacy formatted tars to the Docker daemon, as identified in the
getLayerSize()function comments.Problem
The current implementation has a significant performance bottleneck when creating tars for the Docker daemon:
addLayerToTar()callslayer.Uncompressed()to get the layer datagetLayerSize()to determine the uncompressed size for the tar headergetLayerSize()callslayer.Uncompressed()again and reads through the entire layer withio.Copy(io.Discard, layerReader)just to calculate the sizeSolution
Added an optimization that detects when all layers have known uncompressed sizes (typically after
docker image saveoperations) and uses a more efficient code path:canOptimizeLayerSizes(): Checks if all image layers have cached uncompressed sizes from previous docker save operationsaddLayerToTarOptimized(): Optimized version that uses cached sizes directly, avoiding the expensive size calculationaddImageToTar(): Routes to the optimized path when beneficialPerformance Improvement
Before:
After (when optimization applies):
This eliminates redundant layer decompression and the expensive discard operation when working with images that have all layers downloaded from the daemon.
The optimization is automatically applied when beneficial and falls back to the original implementation when layer sizes are unknown, ensuring backward compatibility.
Fixes #276.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
docker-images-prod.6aa30f8b08e16409b46e0173d6de2f56.r2.cloudflarestorage.com/tmp/go-build2850353549/b355/remote.test -test.testlogfile=/tmp/go-build2850353549/b355/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.short=true(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)eastus.data.mcr.microsoft.com/tmp/go-build2850353549/b355/remote.test -test.testlogfile=/tmp/go-build2850353549/b355/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.short=true(dns block)myother-insecure-registry.com/tmp/go-build2850353549/b355/remote.test -test.testlogfile=/tmp/go-build2850353549/b355/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.short=true(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.