git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fwd: git diff with “--word-diff-regex” extremely slow compared to “--word-diff”?

From
MSMatthieu S <matthieu.stigler@gmail.com>
Date
Nov 18, 2016, 23:40 UTC
Message-ID
<CAEYvigLz3muWD-QFjMZUn=H3RQoxhTYX9EwB6=aiMjWOEN3CBA@mail.gmail.com>
In-Reply-To
<CAEYvigJ14xYDmRG2N0yTgM4spaaB7s9923w0+e9+QQEeFz0NTQ@mail.gmail.com>
Hi

When giving a custom regex to git diff --word-diff-regex= instead of using the default --word-diff (which splits words on whitespace), git slows down very considerably... I don't understand why such a speed difference?

(this question was asked on stack overflow, but after two month without answer, I'm asking it here instead. Post: http://stackoverflow.com/questions/39027864/git-diff-with-word-diff-regex-extremely-slow-compared-to-word-diff).

Example (sorry, UNIX specific code): create two one-line files, and two 200000-lines files:

echo aaa,bbb ,12,12,15 >file1.txt echo aaa,bbb ,12,12,16 >file2.txt

awk '{for(i=0;i<200000;i++)print}' file1.txt > file1BIG.txt awk '{for(i=0;i<200000;i++)print}' file2.txt > file2BIG.txt

Default --word-diff has no issues with the BIG files (cannot see time difference):

git diff --word-diff file1.txt file2.txt git diff --word-diff file1BIG.txt file2BIG.txt

Now use instead --word-diff-regex= argument (with regex from post: http://stackoverflow.com/questions/10482773/also-use-comma-as-a-word-separator-in-diff )

git diff --word-diff-regex=[^[:space:],] file1.txt file2.txt git diff --word-diff-regex=[^[:space:],] file1BIG.txt file2BIG.txt

Why is the speed so different if one uses --word-diff instead of --word-diff-regex= ? Is it just because my expression is (slightly) more complex than the default one (split on period instead of only whitespace) ? Or is it that the default word-diff is implemented differently/more efficiently? How can I overcome this speed slowdown?

Thanks!!
Matthieu
PS: using git 2.7.4 on Ubuntu 16.04
Next: Jeff King
Message 1 of 4 in “Fwd: git diff with “--word-diff-regex” extremely slow compared to “--word-diff”?”
  1. Matthieu SNov 18, 2016
  2. Jeff KingNov 20, 2016
  3. Matthieu SNov 22, 2016
  4. Jeff KingNov 22, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.