From 5d11f2cd0a46c01818c90ffa23d59dd2ac3374cb Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Wed, 14 Oct 2026 21:11:58 -1000 Subject: Diff without asking xdiff for a minimal result XDF_NEED_MINIMAL turns off the cost limit in xdiff, so a file whose lines were reordered took time quadratic in its length. Such a file of 40,000 lines took 2.1 s and now takes 38 ms. Git leaves it off by default as well. --- source/shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/shared.c b/source/shared.c index 51c92d4..0bd9fe3 100644 --- a/source/shared.c +++ b/source/shared.c @@ -435,7 +435,9 @@ int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new memset(&diff_params, 0, sizeof(diff_params)); memset(&emit_params, 0, sizeof(emit_params)); memset(&emit_cb, 0, sizeof(emit_cb)); - diff_params.flags = XDF_NEED_MINIMAL; + // Without XDF_NEED_MINIMAL, as git diffs by default: on a file whose + // lines were reordered, a minimal diff costs time quadratic in its + // length. if (ignorews) diff_params.flags |= XDF_IGNORE_WHITESPACE; emit_params.ctxlen = context > 0 ? context : DEFAULT_DIFF_CONTEXT; -- cgit 2.12.1