From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#71094: [PATCH] Prefer to run find and grep in parallel in rgrep Date: Tue, 21 May 2024 10:35:07 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2676"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Glenn Morris , dmitry@gutov.dev To: 71094@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 21 16:36:11 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s9Qb4-0000SR-Vg for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 21 May 2024 16:36:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9Qas-0000GE-Rb; Tue, 21 May 2024 10:35:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9Qar-0000Fv-5g for bug-gnu-emacs@gnu.org; Tue, 21 May 2024 10:35:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9Qaq-0002F3-Tj for bug-gnu-emacs@gnu.org; Tue, 21 May 2024 10:35:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s9Qav-0007H9-TL for bug-gnu-emacs@gnu.org; Tue, 21 May 2024 10:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 21 May 2024 14:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71094 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.171630212327947 (code B ref -1); Tue, 21 May 2024 14:36:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 May 2024 14:35:23 +0000 Original-Received: from localhost ([127.0.0.1]:49465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9QaI-0007Gh-Rv for submit@debbugs.gnu.org; Tue, 21 May 2024 10:35:23 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56000) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9QaF-0007Ga-DK for submit@debbugs.gnu.org; Tue, 21 May 2024 10:35:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9Qa8-0008Dh-Qa for bug-gnu-emacs@gnu.org; Tue, 21 May 2024 10:35:13 -0400 Original-Received: from mxout1.mail.janestreet.com ([38.105.200.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9Qa5-00023o-Ga for bug-gnu-emacs@gnu.org; Tue, 21 May 2024 10:35:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1716302107; bh=jglpTl5xjQaurrWecGMRyL2FNqPUq09Tg9kfSp3U0jI=; h=From:To:Cc:Subject:Date; b=wErw/MrsVsv7MhTMgVBH/26TIVWoX8Lwa1kL5bCWLJ+ejpBZkRt3Ed6Yz4aZa2zOa EvBftLDVf9SdNiNmTb79NngR3L3MVThioC4Oygz/fSwu5Cw9bPtR9f0D201KkbQoNn 0uEPZdVrQ13ZQGU/BhPuiGpzwhAbP5BqtH+3bMAXm9u32Ui/z4K3zizrM9b2AHHn2r hmHcrJvQYu/4d2zCG85XsQfGV+mhv/opy5z6SaLj1LleUBKi7ueXiHb8OdxLzBRMno Moy5zdjsXMuNY0H9d+nrpG0FUDITT/pjlqlbmLezKr3Zfn3hTkUw0AAqSMLkctyEsx cizUcGz7boVgQ== Received-SPF: pass client-ip=38.105.200.78; envelope-from=sbaugh@janestreet.com; helo=mxout1.mail.janestreet.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285538 Archived-At: --=-=-= Content-Type: text/plain Tags: patch grep.el prefers to run "find" and "xargs grep" in a pipeline, which means that "find" can continue searching the filesystem while "xargs grep" searches files. If find and xargs don't support the flags required for this behavior, grep.el will fall back to using the -exec flags to "find", which meant "find" will wait for each "grep" process to complete before continuing to search the filesystem tree. This behavior is controlled by grep-find-use-xargs; `gnu' produces the pipeline and `exec' is the slower fallback. In f3ca7378c1336b3ff98ecb5a99a98c7b2eceece9, the `exec-plus' option was added for grep-find-use-xargs, which improves on `exec' by running one "grep" process to search multiple files, which `gnu' (by using xargs) already did. However, the change erroneously added the `exec-plus' case before the `gnu' case in the autodetection code in grep-compute-defaults, so `exec-plus' would be used even if `gnu' was supported. This change just swaps the two cases, so the faster `gnu' option is once again used in preference to `exec-plus'. In my benchmarking on a large repository, this provides a ~40% speedup. In GNU Emacs 29.2.50 (build 11, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2024-05-15 built on igm-qws-u22796a Repository revision: 734740051bd377d24899d08d00ec8e1bb8e00e00 Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.9 (Green Obsidian) Configured using: 'configure -C --with-x-toolkit=lucid --with-gif=ifavailable' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Prefer-to-run-find-and-grep-in-parallel-in-rgrep.patch >From 06f0683b51088e4c1c080408624f310d6561a381 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Tue, 21 May 2024 10:32:45 -0400 Subject: [PATCH] Prefer to run find and grep in parallel in rgrep grep.el prefers to run "find" and "xargs grep" in a pipeline, which means that "find" can continue searching the filesystem while "xargs grep" searches files. If find and xargs don't support the flags required for this behavior, grep.el will fall back to using the -exec flags to "find", which meant "find" will wait for each "grep" process to complete before continuing to search the filesystem tree. This behavior is controlled by grep-find-use-xargs; `gnu' produces the pipeline and `exec' is the slower fallback. In f3ca7378c1336b3ff98ecb5a99a98c7b2eceece9, the `exec-plus' option was added for grep-find-use-xargs, which improves on `exec' by running one "grep" process to search multiple files, which `gnu' (by using xargs) already did. However, the change erroneously added the `exec-plus' case before the `gnu' case in the autodetection code in grep-compute-defaults, so `exec-plus' would be used even if `gnu' was supported. This change just swaps the two cases, so the faster `gnu' option is once again used in preference to `exec-plus'. In my benchmarking on a large repository, this provides a ~40% speedup. * lisp/progmodes/grep.el (grep-compute-defaults): Prefer `gnu'. for grep-find-use-xargs over `exec-plus'. --- lisp/progmodes/grep.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 657349cbdff..04056e13685 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -812,15 +812,15 @@ grep-compute-defaults (unless grep-find-use-xargs (setq grep-find-use-xargs (cond - ((grep-probe find-program - `(nil nil nil ,(null-device) "-exec" "echo" - "{}" "+")) - 'exec-plus) ((and (grep-probe find-program `(nil nil nil ,(null-device) "-print0")) (grep-probe xargs-program '(nil nil nil "-0" "echo"))) 'gnu) + ((grep-probe find-program + `(nil nil nil ,(null-device) "-exec" "echo" + "{}" "+")) + 'exec-plus) (t 'exec)))) (unless grep-find-command -- 2.39.3 --=-=-=--