diff options
| author | Arnold D. Robbins <arnold@skeeve.com> | 2025-11-22 20:10:20 -0500 |
|---|---|---|
| committer | Arnold D. Robbins <arnold@skeeve.com> | 2025-11-22 20:10:20 -0500 |
| commit | d12be45fc8e20f8b9e6b8d9763be4d4f68536bfd (patch) | |
| tree | bba7ee2c724ee230c33ed6c868b4df1bddbb0bb7 | |
| parent | 22661edb57e47a2f7cca54c896597a6e6441d9d1 (diff) | |
Improve performance reading from regular files.
| -rw-r--r-- | ChangeLog | 10 | ||||
| -rw-r--r-- | NEWS | 5 | ||||
| -rw-r--r-- | io.c | 22 |
3 files changed, 35 insertions, 2 deletions
@@ -1,3 +1,13 @@ +2025-11-22 Arnold D. Robbins <arnold@skeeve.com> + + Improve raw I/O speed by not checking for a timeout + when there's no need. Issue noticed during profiling + of something unrelated. + + * io.c (file_can_timeout): New routine. Returns true if an + input file is one that can timeout. Regular files cannot. + (get_a_record): Use it. + 2025-11-16 Arnold D. Robbins <arnold@skeeve.com> * io.c (inetfile): Issue a warning if udp is used. It's @@ -60,7 +60,10 @@ Changes from 5.3.x to 5.4.0 It never worked very well. It will be removed in version 6.0. Gawk issues a warning when attempting to use it. -12. As usual, a number of small bugs have been fixed; see the ChangeLog +12. Reading regular disk input files should be somewhat faster now, + since gawk no longer checks for timeouts on such files. + +13. As usual, a number of small bugs have been fixed; see the ChangeLog for the details. Changes from 5.3.2 to 5.3.x @@ -3933,6 +3933,26 @@ errno_io_retry(void) } } +/* file_can_timeout --- return true if file i/o might could timeout */ + +static inline bool +file_can_timeout(IOBUF *iop) +{ + switch (iop->public.sbuf.st_mode & S_IFMT) { + case S_IFIFO: + case S_IFSOCK: + return true; + case S_IFCHR: + return isatty(iop->public.fd); + case S_IFBLK: + case S_IFDIR: + case S_IFLNK: + case S_IFREG: + default: + return false; + } +} + /* * get_a_record --- read a record from IOP into out, * its length into len, and set RT. @@ -3957,7 +3977,7 @@ get_a_record(char **out, /* pointer to pointer to data */ if (at_eof(iop) && no_data_left(iop)) return EOF; - if (read_can_timeout) + if (file_can_timeout(iop) && read_can_timeout) read_timeout = get_read_timeout(iop); if (iop->public.get_record != NULL) { |
