Subject: bug#78520: 31.0.50; Performance issue in dired+isearch with dired-isearch-filenames

From: Michael Heerdegen <[email-masked]>
Date: Thu, 05 Jun 2025 01:41:26 +0200

Juri Linkov <[email-masked]> writes:

> > I had a pending fix for Bug#73018 that caused the bad performance.
> > Without it I see a very good performance.
>
> Does the problem reported in bug#73018 still exist?

No, the problem discussed there seems to be fixed.  Good :-)

> > One small thing I noticed (but that does not have a large impact) was
> > that `search-within-boundaries' is called repeatedly, and the binding
> > #+begin_src emacs-lisp
> > (subregexp
> >   (and isearch-regexp
> >        (save-match-data
> >          (catch 'subregexp
> >            (while (string-match "\\^\\|\\$" string i)
> >              (setq i (match-end 0))
> >              (when (subregexp-context-p string (match-beginning 0))
> >                ;; The ^/$ is not inside a char-range or escaped.
> >                (throw 'subregexp t)))))))
> > #+end_src
> > is computed every time with the same bindings in effect.  This could
> > maybe be factored out (i.e., the computation could maybe be moved
> > upwards in the call tree).
>
> This would require adding a new buffer-local variable
> with an ad-hoc name.

Or some kind of reorganisation of the whole logic of the involved
functions, but that's just not worth the trouble.  (buffer-local
variable... would we not want to support multi isearch?)

But let me please come back to wdired, I have some questions about that
before I continue to experiment:

1.  In `wdired-change-to-wdired-mode', we do this:

| (when wdired-search-replace-filenames
|   (add-function :around (local 'isearch-search-fun-function)
|                 #'dired-isearch-search-filenames
|                 '((isearch-message-prefix . "filename ")))
|   (setq-local replace-search-function
|               (setq-local replace-re-search-function
|                           (funcall isearch-search-fun-function)))
|   ;; Original dired hook removes dired-isearch-search-filenames that
|   ;; is needed outside isearch for lazy-highlighting in query-replace.
|   (remove-hook 'isearch-mode-hook #'dired-isearch-filenames-setup t))

Does that mean that after switching to wdired there is no way to switch
between filename-only and normal search and replace?  Is the behavior
determined when switching to wdired, or can it still be change while in
wdired-mode?

2.  How was that - was it possible to control whether to search and
replace in the symlink targets?

TIA,

Michael.