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

[PATCH 2/3] xdiff: avoid unnecessary memory allocations

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 17, 2021, 11:20 UTC
Message-ID
<eef46c71840d7f36b503a92b899c95632c023351.1637148025.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1079.git.1637148025.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

rindex and ha are only used by xdl_cleanup_records() which is not called by the histogram or patience algorithms. The perf test results show a small reduction in run time but that is probably within the noise.

Test HEAD^ HEAD ----------------------------------------------------------------------------- 4000.1: log -3000 (baseline) 0.19(0.17+0.02) 0.19(0.12+0.07) +0.0% 4000.2: log --raw -3000 (tree-only) 0.98(0.78+0.20) 0.98(0.81+0.16) +0.0% 4000.3: log -p -3000 (Myers) 4.81(4.15+0.64) 4.81(4.23+0.56) +0.0% 4000.4: log -p -3000 --histogram 5.87(5.19+0.66) 5.83(5.11+0.70) -0.7% 4000.5: log -p -3000 --patience 5.35(4.60+0.73) 5.31(4.61+0.69) -0.7%

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 xdiff/xprepare.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
index 7fae0727a02..4527a4a07c4 100644
--- a/xdiff/xprepare.c
+++ b/xdiff/xprepare.c
@@ -213,10 +213,13 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
 		goto abort;
 	memset(rchg, 0, (nrec + 2) * sizeof(char));
 
-	if (!(rindex = (long *) xdl_malloc((nrec + 1) * sizeof(long))))
-		goto abort;
-	if (!(ha = (unsigned long *) xdl_malloc((nrec + 1) * sizeof(unsigned long))))
-		goto abort;
+	if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
+	    (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF)) {
+		if (!(rindex = xdl_malloc((nrec + 1) * sizeof(*rindex))))
+			goto abort;
+		if (!(ha = xdl_malloc((nrec + 1) * sizeof(*ha))))
+			goto abort;
+	}
 
 	xdf->nrec = nrec;
 	xdf->recs = recs;
-- 
gitgitgadget
Previous: Johannes SchindelinNext: Phillip Wood via GitGitGadget
Message 13 of 15 in “xdiff: speedup histogram diff”
  1. 0/3 xdiff: speedup histogram diffPhillip Wood via GitGitGadget, Nov 17, 2021
  2. 1/3 diff histogram: intern stringsPhillip Wood via GitGitGadget, Nov 17, 2021
  3. Derrick StoleeNov 17, 2021
  4. Jeff KingNov 17, 2021
  5. Phillip WoodNov 17, 2021
  6. Johannes SchindelinNov 18, 2021
  7. Jeff KingNov 18, 2021
  8. Phillip WoodNov 19, 2021
  9. Jeff KingNov 19, 2021
  10. Ævar Arnfjörð BjarmasonNov 19, 2021
  11. Jeff KingNov 19, 2021
  12. Johannes SchindelinNov 19, 2021
  13. 2/3 xdiff: avoid unnecessary memory allocationsPhillip Wood via GitGitGadget, Nov 17, 2021
  14. 3/3 xdiff: simplify comparisonPhillip Wood via GitGitGadget, Nov 17, 2021
  15. Johannes SchindelinNov 18, 2021

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.