From f53b77dcfee44156aa2ead90748dca3df4c0b710 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 6 Mar 2024 20:29:45 +0000 Subject: ash: fix 'read' built-in performance regression Commits 8e6991733 and b2901ce8e fixed problems with the 'read' shell built-in when the '-t' option was used. However, they result in a performance penalty. This pipeline: seq -w 0 999999 | while read line; do :; done takes 10 times longer than prior to the changes. If no timeout is specified don't call poll(2). Costs 16 bytes in a 32-bit build; 0 in 64-bit. --- shell/shell_common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/shell_common.c b/shell/shell_common.c index da157ea0e..7fb5f8c58 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -221,6 +221,10 @@ shell_builtin_read(struct builtin_read_params *params) errno = 0; pfd[0].events = POLLIN; //TODO race with a signal arriving just before the poll! +#if ENABLE_PLATFORM_MINGW32 + /* Don't poll if timeout is -1, it hurts performance. */ + if (timeout >= 0) +#endif if (poll(pfd, 1, timeout) <= 0) { /* timed out, or EINTR */ err = errno; -- cgit v1.2.3-55-g6feb