unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71094: [PATCH] Prefer to run find and grep in parallel in rgrep
@ 2024-05-21 14:35 Spencer Baugh
  2024-05-21 20:00 ` Dmitry Gutov
  2024-05-22 11:59 ` Eli Zaretskii
  0 siblings, 2 replies; 29+ messages in thread
From: Spencer Baugh @ 2024-05-21 14:35 UTC (permalink / raw)
  To: 71094; +Cc: Glenn Morris, dmitry

[-- Attachment #1: Type: text/plain, Size: 1587 bytes --]

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'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Prefer-to-run-find-and-grep-in-parallel-in-rgrep.patch --]
[-- Type: text/patch, Size: 2293 bytes --]

From 06f0683b51088e4c1c080408624f310d6561a381 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
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


^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2024-07-03 13:42 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-21 14:35 bug#71094: [PATCH] Prefer to run find and grep in parallel in rgrep Spencer Baugh
2024-05-21 20:00 ` Dmitry Gutov
2024-05-22 11:59 ` Eli Zaretskii
2024-05-22 12:34   ` Dmitry Gutov
2024-05-22 13:50     ` Eli Zaretskii
2024-05-22 14:22       ` Dmitry Gutov
2024-05-22 14:42         ` Eli Zaretskii
2024-05-22 14:50           ` Dmitry Gutov
2024-05-22 15:26             ` Eli Zaretskii
2024-05-22 17:47               ` Dmitry Gutov
2024-05-22 18:21                 ` Eli Zaretskii
2024-05-22 18:06               ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-22 18:30                 ` Eli Zaretskii
2024-05-22 19:15                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-23  4:46                     ` Eli Zaretskii
2024-05-23 13:24                       ` Dmitry Gutov
2024-05-24 17:44                         ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-26 15:57                           ` Dmitry Gutov
2024-05-22 18:51                 ` Dmitry Gutov
2024-05-22 19:36                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-22 19:59                     ` Dmitry Gutov
2024-05-22 12:54   ` Spencer Baugh
2024-05-26  9:47     ` Eli Zaretskii
2024-05-30 12:29       ` Spencer Baugh
2024-05-30 14:52         ` Eli Zaretskii
2024-06-28 14:03           ` Spencer Baugh
2024-06-30  5:07             ` Stefan Kangas
2024-07-03 12:53               ` Spencer Baugh
2024-07-03 13:42                 ` Andrea Corallo

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).