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

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

From
Jeff King <peff@peff.net>
Date
Nov 20, 2016, 20:17 UTC
Message-ID
<20161120201744.7ym4gsmjoijw6oow@sigill.intra.peff.net>
In-Reply-To
<CAEYvigLz3muWD-QFjMZUn=H3RQoxhTYX9EwB6=aiMjWOEN3CBA@mail.gmail.com>
On Fri, Nov 18, 2016 at 03:40:22PM -0800, Matthieu S wrote:
Show 5 quoted lines
> 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?
I think it's probably both.

See diff.c:find_word_boundaries(). If there's no regex, we use a simple loop over isspace() to find the boundaries. I don't recall anybody measuring the performance before, but I'm not surprised to hear that matching a regex is slower.

If I look at the output of "perf", though, it looks like we also spend a lot more time in xdl_clean_mmatch(). Which isn't surprising. Your regex treats commas as boundaries, which is going to generate a lot more matches for this particular data set (though the output is the same, I think, because of the nature of the change).

I would have expected "--word-diff-regex=[^[:space:]]" to be faster than your regex, though, and it does not seem to be.

-Peff
Previous: Matthieu SNext: Matthieu S
Message 2 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.