From 29717eb02920eda35c810b444f7fa7b190155170 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 18 May 2017 22:10:04 +0000 Subject: [PATCH] sh: Keep output buffer across builtins. Allocating and deallocating repeatedly the 1024-byte buffer for stdout from builtins costs CPU time for little or no benefit. A simple loop containing builtins that write to a file descriptor, such as i=0; while [ "$i" -lt 1000000 ]; do printf .; i=$((i+1)); done >/dev/null is over 10% faster in a simple benchmark on an amd64 virtual machine. --- bin/sh/output.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/bin/sh/output.c b/bin/sh/output.c index c3458272785e..ced01d246a1c 100644 --- a/bin/sh/output.c +++ b/bin/sh/output.c @@ -254,14 +254,7 @@ flushout(struct output *dest) void freestdout(void) { - INTOFF; - if (output.buf) { - ckfree(output.buf); - output.nextc = NULL; - output.buf = NULL; - output.bufend = NULL; - } - INTON; + output.nextc = output.buf; }