internal/format: buffer newlineWriter writes

Most writes in the cmd/age Writer stack are chunk-sized, so
approximately 64KiB. However, the newlineWriter, which splits lines at
64 columns, was doing a Write on the underlying Writer for each line,
making chunks effectively 48 bytes (before base64). There is no
buffering underneath it, so it was resulting in a lot of write syscalls.

Add a reusable bytes.Buffer to buffer the output of each
(*newlineWriter).Write call, and Write it all at once on the
destination.

This makes --armor just 50% slower than plain, instead of 10x.

Fixes #167
This commit is contained in:
Filippo Valsorda
2021-01-03 09:10:21 -05:00
committed by Filippo Valsorda
parent cb4d1de4b7
commit 02ee8b969a
2 changed files with 18 additions and 13 deletions
+2 -1
View File
@@ -154,7 +154,8 @@ func main() {
}
}
var in, out io.ReadWriter = os.Stdin, os.Stdout
var in io.Reader = os.Stdin
var out io.Writer = os.Stdout
if name := flag.Arg(0); name != "" && name != "-" {
f, err := os.Open(name)
if err != nil {