-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to support caching compression. (#867)
* Refactor to support caching compression. Today `tarball.LayerFromOpener` must either compress or decompress its input based on which it receives. Virtually all clients of this interface have an uncompressed tarball they want to turn into a layer, but the API we have presents two fun problems. 1. If we simply present the uncompressed tarball (as most clients do) then we will often end up compressing the layer (expensive!) twice. The first time is to compute the layer's digest, and the second is typically to publish the layer as part of `remote.Write`. 2. If we present a precompressed tarball (as ko does), then we will have an extra decompression (less expensive, but still redundant) to compute the diff id. This refactors the layer to store an opener for each form of the layer. The constructor sniffs whether the layer is compressed and based on this makes the "other" opener (that requires conversion) a lazy thunk that performs the conversion each time (this is effectively what we were doing before based on the stored `compressed` bit). The advantage of this approach is that by setting them up before option evaluation we can make them memoizing on their first invocation. Given that most consumers of this library only pass the uncompressed form (or should), I have only provided an option for memoizing the compression. * Fix style stuff * Add a detailed comment for LayerFromOpener with practical learnings * Update comments * Try renaming variables * Fix the Gunzip utility's close bug
- Loading branch information
Showing
3 changed files
with
107 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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