diff options
author | Ron Yorston <rmy@pobox.com> | 2024-03-06 20:29:45 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-03-06 20:37:54 +0000 |
commit | f53b77dcfee44156aa2ead90748dca3df4c0b710 (patch) | |
tree | 506cd07e4d960440728c553b6ccc45c768911cab | |
parent | 1273a1ddcab67c8ccca61c7c7c52c6049be4c336 (diff) | |
download | busybox-w32-f53b77dcfee44156aa2ead90748dca3df4c0b710.tar.gz busybox-w32-f53b77dcfee44156aa2ead90748dca3df4c0b710.tar.bz2 busybox-w32-f53b77dcfee44156aa2ead90748dca3df4c0b710.zip |
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.
-rw-r--r-- | shell/shell_common.c | 4 |
1 files changed, 4 insertions, 0 deletions
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) | |||
221 | errno = 0; | 221 | errno = 0; |
222 | pfd[0].events = POLLIN; | 222 | pfd[0].events = POLLIN; |
223 | //TODO race with a signal arriving just before the poll! | 223 | //TODO race with a signal arriving just before the poll! |
224 | #if ENABLE_PLATFORM_MINGW32 | ||
225 | /* Don't poll if timeout is -1, it hurts performance. */ | ||
226 | if (timeout >= 0) | ||
227 | #endif | ||
224 | if (poll(pfd, 1, timeout) <= 0) { | 228 | if (poll(pfd, 1, timeout) <= 0) { |
225 | /* timed out, or EINTR */ | 229 | /* timed out, or EINTR */ |
226 | err = errno; | 230 | err = errno; |