From 4c83fcf365a1aa52222b036e60198d84806feea2 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Mon, 7 Aug 2023 16:42:28 -0500 Subject: [PATCH] Avoid unnecessary map allocation when writing progress `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 --- util/progress/multiwriter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/progress/multiwriter.go b/util/progress/multiwriter.go index a856db8caa09..7cce8a7ca7d2 100644 --- a/util/progress/multiwriter.go +++ b/util/progress/multiwriter.go @@ -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 {