From patchwork Tue Apr 4 19:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 13200933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4F43C761A6 for ; Tue, 4 Apr 2023 19:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236000AbjDDTve (ORCPT ); Tue, 4 Apr 2023 15:51:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbjDDTvd (ORCPT ); Tue, 4 Apr 2023 15:51:33 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A8FA8 for ; Tue, 4 Apr 2023 12:51:31 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id v6-20020a05600c470600b003f034269c96so10522473wmo.4 for ; Tue, 04 Apr 2023 12:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680637890; x=1683229890; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=vOWWptlMwS7x0v9qMR/X7GZF8/y6INJkVuY+7+tB2Ok=; b=B/jK6oynLNtlTK4EmIKgfS7Kq1wKAg9FsdAPMkiO0kqRPx+wRJhakiXjBJgDV2DK3y 4RVF0smEnPxJ9pcNA2O8goExiZ295/2TJ0RM8xwIjNmadWjZT5FHPHIXuuy8AXTOJzXw qDy1Bn0aGEpndIAbZQpzaKPkSzUsiF1hK2zzjovxLDr2CcYpM+EeDEeLUcYrwr4DxpBN 5uOTfWoO8F9STxUbR+aT70t10N+u86a+QcDsj5bVVRrhEea9CVls5tWqyyFVceZH+u1x pCHQycH5PZMrZ2zIkdSnOKrqIXJBb/VP4kIpr6yEBHxcXOsxiXNckRJHyGdyiyF3kJ0d 0VNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680637890; x=1683229890; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vOWWptlMwS7x0v9qMR/X7GZF8/y6INJkVuY+7+tB2Ok=; b=5+iEHppUnuqPHeqQr/8e2xvld59nJNLM/Gj3bW/74uY15VeOPKPlvkClkAlkSD0PWH TiYagXh7Nqgdkil6x1Q6I3XFUtFacHYBqAdT7+3/g+yz81i4nAvorAzYG5gv2qf2/zM3 n6i266ajzu357kWFIQ7/PJwltGh4dJq14vgmaNNLoNfQqtcKmiaJ4TGDmdZKfD6LRmxQ AliGMKqIcsu3NvMiW1MWF422YoCHIx3QHPcPwJa/5LlziIb+uFkfkESd5elQFEZ7AGhZ g5GTz0m1zAvaYkPddVxJk12Abz/uEHUBbkL7yPXllltIXFHED5EJfdv/9lmRYixVzxh9 +7dw== X-Gm-Message-State: AAQBX9fjyzctcP9Zww0DUYyKXwWt21yDomvtv4IfcpwuVC7qg0sOQ1i2 lf9+NcAdPkHcn29k2QYx/xgiFcTtDjU= X-Google-Smtp-Source: AKy350ZUH+AhJtzt3t99zPhUvMuKD6YdVE+qvjEbRH4uSOO6GRHtalZiOu8cPVAHyvaY69ggS/yXUQ== X-Received: by 2002:a7b:cd0d:0:b0:3eb:42fc:fb30 with SMTP id f13-20020a7bcd0d000000b003eb42fcfb30mr3107927wmj.32.1680637890271; Tue, 04 Apr 2023 12:51:30 -0700 (PDT) Received: from [192.168.0.160] ([170.253.51.134]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c1c1700b003ee443bf0c7sm23159227wms.16.2023.04.04.12.51.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Apr 2023 12:51:29 -0700 (PDT) Message-ID: Date: Tue, 4 Apr 2023 21:51:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Content-Language: en-US To: Git Mailing List , Alejandro Colomar From: Alejandro Colomar Subject: Dubious diff using --diff-algorithm=histogram Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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: Cheers, Alex --- 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..92bdfb1f 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: - if (nxt_slow_path(end - p < 10)) { - 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..92bdfb1f 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; } alx@asus5775:~/src/nginx/unit/space$ git diff --diff-algorithm=myers diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 8646a6ce..92bdfb1f 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: - if (nxt_slow_path(end - p < 10)) { - p++; + if (nxt_slow_path(end - p < 10)) { + if (p == end) { return NXT_AGAIN; } alx@asus5775:~/src/nginx/unit/space$ git diff --diff-algorithm=minimal diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 8646a6ce..92bdfb1f 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: - if (nxt_slow_path(end - p < 10)) { - p++; + if (nxt_slow_path(end - p < 10)) { + if (p == end) { return NXT_AGAIN; }