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

Re: Dubious diff using --diff-algorithm=histogram

From
ACAlejandro Colomar <alx.manpages@gmail.com>
Date
Apr 4, 2023, 19:53 UTC
Message-ID
<0f90f1a0-56bc-7ca4-e276-9c163ec8ec2c@gmail.com>
In-Reply-To
<a0b6d751-25fd-a132-f8a5-9844e5d9b8a6@gmail.com>
On 4/4/23 21:51, Alejandro Colomar wrote:
Show 17 quoted lines
> Hi,
> 
> I've met some strange diff with the histogram algorithm.  I know this
> has a lot of magic in it, and it's probably not so trivial to improve,
> and maybe my code base is so weird that it makes the histogram do crazy
> stuff, but I wanted to show it to you in case there's anything that can
> be improved.
> 
> So, patience is showing a better diff than histogram, which shouldn't
> happen usually, and less in this case, where p++ is such a common thing
> to do (although maybe this nxt_slow_path() macro is called a lot in the
> file and confuses the histogram?).
> 
> Code base: <https://github.com/nginx/unit.git>
> 
> Cheers,
> Alex
Now this has surprised me even more:
alx@asus5775:~/src/nginx/unit/space$ git diff --diff-algorithm=histogram 
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 8646a6ce..3559f2e2 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -340,9 +340,9 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
 
 space_after_target:
 
-    if (nxt_slow_path(end - p < 10)) {
+    p++;
 
-        p++;
+    if (nxt_slow_path(end - p < 10)) {
 
         if (p == end) {
             return NXT_AGAIN;
alx@asus5775:~/src/nginx/unit/space$ git diff --diff-algorithm=patience 
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 8646a6ce..3559f2e2 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -340,10 +340,10 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
 
 space_after_target:
 
+    p++;
+
     if (nxt_slow_path(end - p < 10)) {
 
-        p++;
-
         if (p == end) {
             return NXT_AGAIN;
         }
-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
Previous: Alejandro ColomarNext: Alejandro Colomar
Message 2 of 3 in “Dubious diff using --diff-algorithm=histogram”
  1. Alejandro ColomarApr 4, 2023
  2. Alejandro ColomarApr 4, 2023
  3. Alejandro ColomarApr 28, 2023

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.