Skip to content

Commit

Permalink
Avoid unnecessary map allocation when writing progress
Browse files Browse the repository at this point in the history
`MultiWriter` would create an unnecessary map allocation when the
`Write` method was used. The `Write` method would create a progress
object with the meta field initialized to the meta field of the writer
itself. It then invoked its own `WriteRawProgress` method which would
see two maps with the metadata and erroneously believe that they were
different and needed to be merged into a single metadata map.

Since this map is initialized with the metadata of the writer before
`WriteRawProgress` is invoked, this merge was unnecessary and could add
a lot of unnecessary memory allocations during a build.

This changes the `MultiWriter.Write` method to invoke the private
`writeRawProgress` which performs the actual write and avoids the
metadata merge.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
(cherry picked from commit 4c83fcf)
  • Loading branch information
jsternberg authored and tonistiigi committed Aug 23, 2023
1 parent 2a6aace commit 58e3af5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion util/progress/multiwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (ps *MultiWriter) Write(id string, v interface{}) error {
Sys: v,
meta: ps.meta,
}
return ps.WriteRawProgress(p)
return ps.writeRawProgress(p)
}

func (ps *MultiWriter) WriteRawProgress(p *Progress) error {
Expand Down

0 comments on commit 58e3af5

Please sign in to comment.