FYI, when investigating the big-hole failure, I noticed that its use of grep took 4.0s of user time and ~7s of system, but with this change, the user-time component went down to 2.0 seconds and the 7s stayed the same.
>From 8c74af84958634a22a24dbc7fecf3fafd3f8e4bd Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Mon, 30 Jul 2012 11:39:29 +0200 Subject: [PATCH] maint: optimize long-line processing * src/main.c (grep): Use memrchr rather than an open-coded loop, reducing the cost of the replaced code by 50% when processing very long lines. If there were a rawmemrchr function (analogous to glibc's rawmemchr), then the performance improvement would be even greater. --- src/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 84066d8..e3b5186 100644 --- a/src/main.c +++ b/src/main.c @@ -1200,8 +1200,10 @@ grep (int fd, struct stat const *st) the buffer, 0 means there is no incomplete last line). */ oldc = beg[-1]; beg[-1] = eol; - for (lim = buflim; lim[-1] != eol; lim--) - continue; + /* FIXME: use rawmemrchr if/when it exists, since we have ensured + that this use of memrchr is guaranteed never to return NULL. */ + lim = memrchr (beg - 1, eol, buflim - beg + 1); + ++lim; beg[-1] = oldc; if (lim == beg) lim = beg - residue; -- 1.7.12.rc1
