Skip to content

Commit

Permalink
Add 4MiB bufio for pgzip
Browse files Browse the repository at this point in the history
This reduces BuildTarball latency by ~10%.

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr committed Jul 8, 2023
1 parent 68e80b9 commit 4068d56
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/build/build_implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package build

import (
"bufio"
"context"
"crypto/sha256"
"errors"
Expand Down Expand Up @@ -99,7 +100,8 @@ func (di *buildImplementation) BuildTarball(ctx context.Context, o *options.Opti

digest := sha256.New()

gzw := gzip.NewWriter(io.MultiWriter(digest, outfile))
buf := bufio.NewWriterSize(outfile, 1<<22)
gzw := gzip.NewWriter(io.MultiWriter(digest, buf))

diffid := sha256.New()

Expand All @@ -110,6 +112,10 @@ func (di *buildImplementation) BuildTarball(ctx context.Context, o *options.Opti
return "", nil, nil, 0, fmt.Errorf("closing gzip writer: %w", err)
}

if err := buf.Flush(); err != nil {
return "", nil, nil, 0, fmt.Errorf("flushing %s: %w", outfile.Name(), err)
}

stat, err := outfile.Stat()
if err != nil {
return "", nil, nil, 0, fmt.Errorf("stat(%q): %w", outfile.Name(), err)
Expand Down

0 comments on commit 4068d56

Please sign in to comment.