From 1c00035b4120a15f2cbfca933f3d407040b7c2e1 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 17:09:13 -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: 2.1 s for one of 40000 lines, now 38 ms. Git leaves it off by default as well. --- source/shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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