Subject: bug#72723: [bug-diffutils] bug#72723: diff -d can be very slow

From: Vincent Lefevre <[email-masked]>
Date: Tue, 20 Aug 2024 03:00:55 +0200

[Cc to Stefan Monnier, who introduced -d in GNU Emacs in 2007]

On 2024-08-19 17:17:27 -0700, Paul Eggert wrote:
> On 2024-08-19 16:55, Vincent Lefevre wrote:
> > When opening a .diff file, GNU Emacs runs "diff -ad" on 2 files
> > it has built (I suppose that the reason is to get a word diff),
> > and this can be very slow
> 
> That's inherent to the algorithm, no? I don't know of any faster algorithm,
> if you really want minimal output. If you know of one, please let us know.
> 
> A simple workaround would be for GNU Emacs to not use the -d (--minimal)
> option.

Perhaps not possible. In the Emacs code (in lisp/vc/smerge-mode.el),
I could find:

  (let ((coding-system-for-read 'utf-8-emacs))
    (call-process diff-command nil t nil
                  (if (and smerge-refine-ignore-whitespace
                           (not smerge-refine-weight-hack))
                      ;; Pass -a so diff treats it as a text file even
                      ;; if it contains \0 and such.
                      ;; Pass -d so as to get the smallest change, but
                      ;; also and more importantly because otherwise it
                      ;; may happen that diff doesn't behave like
                      ;; smerge-refine-weight-hack expects it to.
                      ;; See https://lists.gnu.org/r/emacs-devel/2007-11/msg00401.html
                      "-awd" "-ad")
                  file1 file2))

I suppose that this is the code that is called, as I couldn't
find another occurrence of -ad. So there is a reference to

  https://lists.gnu.org/r/emacs-devel/2007-11/msg00401.html

(that was with diff (GNU diffutils) 2.8.1) and the latest message
(about the use of -d, in particular):

  https://lists.gnu.org/r/emacs-devel/2007-11/msg00522.html

-- 
Vincent Lefèvre <[email-masked]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)