Subject: bug#64735: 29.0.92; find invocations are ~15x slower because of ignores

From: Eli Zaretskii <[email-masked]>
Date: Tue, 02 Sep 2025 19:37:24 +0300

> Cc: [email-masked]
> Date: Tue, 02 Sep 2025 12:23:10 -0400
> From:  Spencer Baugh via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> Dmitry Gutov <[email-masked]> writes:
> 
> > On 20/07/2023 00:16, Spencer Baugh wrote:
> >> In Emacs alone, there are a few things we could do:
> >> - we could mitigate the find bug by optimizing the regexp before we pass
> >> it to find; this should basically remove all the overhead but makes the
> >> find command uglier and harder to edit
> >
> > I like these two approaches.
> 
> Much delayed, but the attached patch implements this optimization
> approach.  In my testing, it provides a substantial speed-up for rgrep.

Thanks.

> +(defcustom grep-find-optimize-matching t

I'd call this grep-find-use-find-regex, or somesuch.

> +This affects ignores from `grep-find-ignored-directories' and
> +`grep-find-ignored-files' and the globs passed as FILES to `rgrep'."
> +  :type 'boolean)

The :version tag is missing.

> +If `grep-find-optimize-matching' is non-nil and ARG is a known valid
> +find argument, then instead return a single \"-regex\" or \"-iregex\"
> +argument which matches all of GLOBS."
> +  (if-let* ((grep-find-optimize-matching)
> +            (known-arg (assoc arg '(("-path" "-regex" 'path)
> +                                    ("-name" "-regex" 'name)
> +                                    ("-ipath" "-iregex" 'path)
> +                                    ("-iname" "-iregex" 'name))))

Isn't the -regex/-iregex option a GNU extension?  If so, this should
only be used with GNU Find.

Also, do we need to use -regextype as well, to make sure the regexp we
produce is interpreted correctly?