From nobody Mon Sep 07 04:20:34 2026 X-Original-To: dev-commits-src-branches@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 4hdYlR0t4dz6rM8H for ; Mon, 07 Sep 2026 04:20:35 +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 4hdYlR0DCWz3SJR for ; Mon, 07 Sep 2026 04:20:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788754835; 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=X3SdQtrysTIJ+u53IAt70quSpPAIHzVQLLzcuX1LRhWye4FPTioIqJNURcVgP6Mhkwr04n Cbbl4jUjxEgrtG2pwi7Taubo9LC91ykez8kuD/NMM/UhCdkiL9ImvXASuEsF950ePCtFNq PcsnX2CwVsm/XeGPoFlA+B9a1NKsadF5+0WcdtQ33Szifyx3HfenwNQWZCIeDJM++HuDjo GDgzCASW94IJgkk8tU4AI8a+pJDJ/5hGkVBxYMBINjBYsgvePHeOYkOGcKu46kEwkERRhz QCGD3K8371lxshN65+rBRUyLLWijrUtos7MtFh8X087Fx8dP0qHOUknH8eSbhQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788754835; a=rsa-sha256; cv=none; b=LvV+QIGRsGYGZk6iWJ+//isnsM+RuOYy5V57DgC1CvtW5aukBgBqk0S6ZaWQK6cU+Mr918 3Zia5jNHyz61hgCGDkAw9fO60Q2J7EKd6511HYUlYwShhDPm27kv5iIAPnqJNLwTS6Ei7U V2VjDy8Z1OO/Xvfkfwi782Z7MWumIP0cWh80OqAffVJrvCD8GysDTeXotryqse56uIu1ZS Y1uWOmjNWOcJEbIS7gh7q0HZhFgpQl9Zk2dOJ7Q69fsNbjFVP5aqPNT6RyBwrzRGpaLWc+ ocBjRSOgJgD090nsR/jDjpjUxtTr7Bbxr2yra/kTXgxiiFqg2Ks8ykUHZj3Rfw== 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=1788754835; 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=PIRaZ1dyjC14XmSlZeHyVJmdTo/UWOUE7UCa/t0YNuZa02QCQdNVjxosJHKyX5TWyXQbly fJb/WRjVBvtFMbQL56QpE+c2/ABEndG8sunqHWYy/O7U3yaa29tEdJ6gNgeD46WrVbFAVu dDGUcj0tSmnA94Ax42sGouLSFyxzkbONbFsg8AfvUhbuqnN3AXev0eQaeVLOrfQCcrzLLh rhWDkaS3oKnoNKMKcoITzI+9Pw0y0d3wrox7h60PygR4lTwwoFNxMhEZLf+JheJqiHbJKI Kn3Se85zZsk+Boz49s1ArwR7wauMqF6D+oMroJikQq5Pww95maFaTT10w83TuQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hdYlQ6M07z12XR for ; Mon, 07 Sep 2026 04:20:34 +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: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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);