#1079088 diffutils: diff -d can be very slow, affecting GNU Emacs

Package:
diffutils
Source:
diffutils
Description:
File comparison utilities
Submitter:
Vincent Lefevre
Date:
2026-01-10 11:04:45 UTC
Severity:
normal
Tags:
#1079088#5
Date:
2024-08-20 00:10:08 UTC
From:
To:
I've just reported the following bug upstream:
------------------------------------------------------------------
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, even though the original .diff file
is rather simple.

I've attached a slow-diff.tar.xz archive with:
  * diff1L52tn0 and diff2U4TVho (files built be GNU Emacs).
  * file.diff the original .diff file.

When running "/usr/bin/emacs -Q file.diff.xz", I could see what
takes the whole time with ps or top. Here I could see

  diff -ad /tmp/diff1L52tn0 /tmp/diff2U4TVho

As this is slow, I could obtain these files.

On my recent machine, "diff -ad diff1L52tn0 diff2U4TVho" takes
27 seconds.
------------------------------------------------------------------

Note that Emacs cannot even be interrupted with C-g (this may be
an additional bug in Emacs).

#1079088#10
Date:
2024-08-20 00:21:10 UTC
From:
To:
I'm attaching it in this message for the Debian bug.
#1079088#15
Date:
2024-08-20 14:14:37 UTC
From:
To:
reassign 1079088 emacs
severity 1079088 normal
thanks

El 20/8/24 a las 2:10, Vincent Lefevre escribió:

As pointed out by Paul Eggert in bug-diffutils, diff -d
is *inherently* slow. This is documented in the diff --help
output:

#1079088#26
Date:
2025-10-01 01:36:35 UTC
From:
To:
Control: forwarded -1 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79546
Control: retitle -1 emacs: opening a diff file in diff-mode can be very slow
Control: found -1 1:30.1+1-6
Control: found -1 1:30.1+1-9
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79546

with a simpler testcase:

$ echo . > file1
$ seq 50000 > file2
$ diff -u file1 file2 > file.diff
$ emacs -Q file.diff

takes 17 seconds on my machine. With 100000 instead of 50000,
this takes 72 seconds, i.e. about 4 times as much.

But I think that the best solution would be a limit detection
in diff, above which the faster (but not giving a minimal diff)
algorithm should be used.

#1079088#43
Date:
2026-01-10 10:10:41 UTC
From:
To:
Es gibt eine Familienspende in Höhe von 1.850.000,00 USD von Cheng Charlie
Saephan. Bitte antworten Sie für weitere Informationen. Denken Sie daran,
Ihrer Familie und den Bedürftigen in Ihrer Umgebung Gutes zu tun.

Dies ist bereits der zweite Versuch, Sie zu erreichen. Bitte antworten Sie
für weitere Details.

#1079088#48
Date:
2026-01-10 10:10:41 UTC
From:
To:
Es gibt eine Familienspende in Höhe von 1.850.000,00 USD von Cheng Charlie
Saephan. Bitte antworten Sie für weitere Informationen. Denken Sie daran,
Ihrer Familie und den Bedürftigen in Ihrer Umgebung Gutes zu tun.

Dies ist bereits der zweite Versuch, Sie zu erreichen. Bitte antworten Sie
für weitere Details.