From nobody Mon Sep 07 04:20:34 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hdYlX3tLJz6rMRq for ; Mon, 07 Sep 2026 04:20:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hdYlX0CrVz3S5b for ; Mon, 07 Sep 2026 04:20:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788754840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7fPGrq56s0y7wqJo23lCvWQbT3bASeeA38Q0DrUAzWk=; b=gZjehGRHJj4iYUu20uCuRMnhlxIMXNA851n3NMdgX2xqOvyDugWkXyxADIHrzcAXjDLi45 UmkWpF+ZPkxlzoNdZ0G33p6Z6pB3VCVvx3kijJPqngrnjucMDALIUl1NM8l28iwVO+Slw1 cGIwIoaYWHXQCKmGuftycVVB/sDsfhH/FdAFw9DuoPYzSAhZBa/Fl5TsH3Bb/J9MuUfeOC CDmfMonjFqsuJ7ALUXYADxd+R+WmtXVMiO9qmH+wf9Tyrzs/9je5h2mm995c7Uc7VA7mjW ZSpgFk4ceaoKJWYqgQ8Xezm147zta4o5RVf+ObIvyYglSHYYPg9jgJ3fpnJEwQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788754840; a=rsa-sha256; cv=none; b=lGhYWAc1xsHOatBpAUuPofu6HR9Pq0fdq61aozT0Nnb0KlNotKJj7m6T5w4Ci/er04Jux4 dAD8YtjolCPfzQkTay1EbCu9UNHn1qN7Pr5Nrn5qTAhz4Hiufr1Yh6FkS+jkIUs4wwOqzz O1jZlyvbfZnqx5IY+IGV58MPP6QDqBeYKir3/GjHhXt5WdUDipDRo4i0Dhf39lKoYDC2hv KxKEh5875LkJG/t5Tun2dESmRZp8T+5WO+AoWHYcjv0+P/fviMy3xGMRe3//Zt1SZfSDcX jRO4R89Kw3l99oJhyjhqPrM3eoua8s24jgp/ZvQKqKLLN36gATcK5fb0R/WZoQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788754840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7fPGrq56s0y7wqJo23lCvWQbT3bASeeA38Q0DrUAzWk=; b=XTO09oxEeZ3V48QY+wWj05n8Wnmq4bKkD1CvdF8vx9NYtDOd+WXYMeHli6i7i2CHqRlrG0 47KtZd/jdM/8uLitTGma+nabzeMGWaJMS2nqSaHQKKzeTutVs1ZCa0Ts3JxswkR8OQQ1SL w5Q4aE/rMF6Dk5f74s7+NBe51cRQyOsMoff+sEWLd7LQznFdKX+O7tX02T1sn1nDosxtZ/ tqfLsj1Zj3/X3MufMB7mXlXK7rbyoDbh6JoYVeMTrw5RVvDZ4bE7FVB2gSRbx+ybHH8ptg 5enim50Dz1E4nzw6X72n1gY96T738DaZJ6WBs0/P42KaFkIHZfWhoWR9nMvWRA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hdYlW6KVNz12dS for ; Mon, 07 Sep 2026 04:20:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1c99b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 07 Sep 2026 04:20:34 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 00681255baff - stable/15 - grep: periodic timer-based fflush instead of unconditional per-line flush List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 00681255baff47f5dcb92eff5a520c07e9248e5b Auto-Submitted: auto-generated Date: Mon, 07 Sep 2026 04:20:34 +0000 Message-Id: <6a9e3b92.1c99b.248894ce@gitrepo.freebsd.org> The branch stable/15 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=00681255baff47f5dcb92eff5a520c07e9248e5b commit 00681255baff47f5dcb92eff5a520c07e9248e5b Author: Baptiste Daroussin AuthorDate: 2026-06-12 12:13:35 +0000 Commit: Baptiste Daroussin CommitDate: 2026-09-07 04:19:00 +0000 grep: periodic timer-based fflush instead of unconditional per-line flush Replace the unconditional fflush(stdout) in grep_printline and procmatches with a periodic timer that flushes at most once every 100ms. This preserves interactive responsiveness (grep | tee, grep | tail -f) while avoiding 1M+ write(2) syscalls when processing large inputs. The flush interval is tracked via clock_gettime(CLOCK_MONOTONIC) and a static timespec. --line-buffered continues to flush immediately via setlinebuf(3), as before. Benchmark on 1M lines (37MB output to file): unconditional fflush: 1.90s (sys 1.22s) periodic 100ms timer: 0.49s (sys 0.007s) Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D57528 (cherry picked from commit ffe47c424e0a45f5d8d20a5944477821bd946eef) --- usr.bin/grep/util.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 5b40405852b3..dbb21dcfd78e 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -724,12 +725,36 @@ grep_strdup(const char *str) * Print an entire line as-is, there are no inline matches to consider. This is * used for printing context. */ -void grep_printline(struct str *line, int sep) { +static struct timespec printline_last_flush = { 0, 0 }; + +static void +flush_if_stalled(void) +{ + struct timespec now; + + if (lbflag && fileeol == '\n') + return; + + clock_gettime(CLOCK_MONOTONIC, &now); + if (now.tv_sec > printline_last_flush.tv_sec || + (now.tv_sec == printline_last_flush.tv_sec && + now.tv_nsec - printline_last_flush.tv_nsec > 100000000)) { + fflush(stdout); + printline_last_flush = now; + } +} + +void +grep_printline(struct str *line, int sep) +{ printline_metadata(line, sep); fwrite(line->dat, line->len, 1, stdout); putchar(fileeol); - fflush(stdout); + if (lbflag) + fflush(stdout); + else + flush_if_stalled(); } static void @@ -836,7 +861,7 @@ printline(struct parsec *pc, int sep, size_t *last_out) *last_out = pc->ln.len; } putchar('\n'); - fflush(stdout); + flush_if_stalled(); } else if (!oflag) { /* * -o is terminated on every match output, so this @@ -847,7 +872,7 @@ printline(struct parsec *pc, int sep, size_t *last_out) */ terminated = false; } else { - fflush(stdout); + flush_if_stalled(); } } else grep_printline(&pc->ln, sep);