From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796066739; b=liz/RWnhULpdP3B02G/AHtBVMylYcegtleslVrnGm1vHLaDD1th1caywOObmt+Nd0V6W Ax9T12R3DBi1cw9IumKpM3NwRzS1nicTP/2dfsGl9aPkgKn8EN7IHW8oVAGqceSMGcETB C0P43BsHoxpHsNX1pd0ZPJvwaN+LNwDkC9XwfvpLei75ujS7kBvJ43SHxNRpmO21Fq0oM OJleYeBR3HujGjkMHaKW70fh/FgQ12RiJWwOBuifLrG7OcMocEHqNznpYghYR5j7/GM6q 1Lftwzbl7bI098k4PJPb3y1r87LTLBYcoKYPrB9iJu+6k8U+K8ZAJbhWM52sAJr/G1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796066739; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:From:Date: Subject:Fcc:Content-Type:Content-Transfer-Encoding:MIME-Version:To: Cc; bh=rMQTSsdnCZXOvKubwg8LrIM9OtzK9KBNdViS0yBYZxo=; b=MqzYWVYNjaZFmkyywWmP2ddULYYvTHvC15+nCFG5Lf7maV4qt0fGT6tVlITwHCQa7oPT 0z0lrduk2uBVRJ/yxtHhNEhBfRi25NZEkA2wwQCLBxj9XvzLY4ONJ1C7b040lbP4MPl6S P0aTdhx5AFgRTQEHjcC6T/MgWHdWGgodqzkPA1+rNrEKKUlRjSAB8SYX22XsutrlFdVrT 7H3mDqqr/zMdXQm0tCD2VyC/dJV7Des1BrhNU1W1rrQKOVYB22TsrU+KJxt1Zhr06D7+f EiVGJ2duDdQbScwL1Sd1p1O9oNPCKa+q5EIdOjMahON4B/x163motY6yC4oW9kcT+Jg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="lBlA1kz/"; arc=none smtp.remote-ip=209.85.161.43 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD3E4606A31C for ; Mon, 30 Nov 2026 19:25:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CD3E4606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lBlA1kz/ Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-71ad047710aso6841257eaf.3 for ; Mon, 30 Nov 2026 11:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796066738; x=1796671538; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=rMQTSsdnCZXOvKubwg8LrIM9OtzK9KBNdViS0yBYZxo=; b=lBlA1kz/RCSNCGTd+b4BA7pA+jxrqJTEfTr2ocnkaSN0+PRmNUMeonMkU48ulTky5G Bm4I82cFz1K6CI1ntsTUGr69c7GxGzgyhInOhmd5q8IwPegdK1sha3oF9PRFjUYtveix Czca5VHVKgxYiKYq2RLXCUpnQoyvhfGW9U7dJZcoVCuc4m++/HE5NiuHEKxo8Q2l3KpP wDH4QakktPZHwA0t5q38UG0gMAdDvy9xaUIH7niqqiTb5dO0EBNX1hOXwoUudkuRzsZt 0xGZSMZEWJx3ySIygGAI1K6d94cNLT1m7IZiBmQUy7FbX67i8IWX4PNckn9MTLBi8/oq +0Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796066738; x=1796671538; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=rMQTSsdnCZXOvKubwg8LrIM9OtzK9KBNdViS0yBYZxo=; b=dSck3wgpnnnYYV1g4lZtqGUumJMK9ePdoOxQDDQONdfrqBdb5szdpXzY1UCymHjqse wuKtAwgQ5KFY3Kd+KcA+E73Hb8ICb+DqGq7PQjr51gjSPOkuLR3mVKowcm2v9Zv8g2ac kIgW2k2zB2izbE0cyWKmFfJKdV9unaRdt8Q1KM/rpOTDdUHjB0BI06R0qeFDnFfTtNmo IxbMb7WuMA8u65EFKulf0RR14qsfTdcbFaH4QWL9TVXu1L3Z5Iae1QyJbVooUMZkRN+l eVOxUZIcWig+P4x5YoKTid5nCs/svhJt2FKkbVFxplKzLuYRCDpTYCq+VTPTdjPLkPUa rpPg== X-Gm-Message-State: APuU4Z8R3rB0MVeKK+4+a24lzxKj1nOwmUEo9SzdeSIUqHK1p099xNR5 BAAjAWc8wQWE0Z8FjEhkF2GnBTqEYtua3GnbDXCQ4gIVilSWcOJUB4FrI7WgPNll X-Gm-Gg: AZFdTZc2PYZtFzlauN8B8EAWdTkP/T4n8T6w24jyde+PdLT+LTFvqiPoBBVaT9fCUW2 ISCnPJyYxp8S88J1Bdq6eka1vQQ3F+f9W3CPCLrGrPaaO5qv06IXAJq2/jO26XUCSUK+K9L+grW /qrcNuOCRj0uO4B9hO4DMToI6k4uwIesR71wfq/Q0rhGN/hFHAmaBFM2lq3J6K5Ku8xYNL1Vss3 bA3wQKgORnRWk2NvarJdeBe1mtY9mmx4ouYBBIlG/671GhC5+J78y9jWABFCPiTdNt/r9JQbwog h9VYKxeUwJscrwvVLVVxGBWg2Pj994NNaSyhO+Smm2uNB7w8G6xcFbW2Ozw1QuyyeIGmIQb/HF/ pzUKx2pSEozYgOCSvOenx+S8DJxQhTlYn2yFdwiRYcDC1De5F5567qrCXS+PpIr1Trir0hl+/GI 2IkwHdNfEyAEaZBatRyGjRVP1ncpBaYj6Rw+S0DfQiaAyZFSdsKGpawVuq6z2BMuWHZ9pvPub3x DzPv7DLuqw7tg/uwzieiMDwHfsXsLTm5Jc1/5DMCYEIum1uhAgq8RBobRXk0ZcgohHnDqrhy/R0 XrmzJ+AOKZPIFTA2IJ8laSN5BRpiex4= X-Received: by 2002:a05:6820:1c8c:b0:71b:7929:cb69 with SMTP id 006d021491bc7-71b7929d4c2mr16467458eaf.24.1796066737562; Mon, 30 Nov 2026 11:25:37 -0800 (PST) Received: from [127.0.0.1] ([20.64.24.251]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b380bdff9sm23824119eaf.11.2026.11.30.11.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 11:25:37 -0800 (PST) Message-Id: From: "Derrick Stolee via GitGitGadget" Date: Mon, 30 Nov 2026 19:25:35 +0000 Subject: [PATCH] delta-islands: revisit trees with new delta marks Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, peff@peff.net, ttaylorr@openai.com, newren@gmail.com, Derrick Stolee , Derrick Stolee From: Derrick Stolee When exploring the object graph to group objects into delta-islands, some trees and blobs can be visited from one path and then revisited later from another. If those two visits come from objects with different delta marks, then the final mark of the visited object should be the union of those marks. Instead, some cases only have the first marks as we don't reprocess objects marked with SEEN. This gets worse for objects recursively reachable from that object. This change includes some test cases that demonstrate this problem, and several of the modes fail without the accompanying code change. These examples were discovered while working with the --path-walk option as integrated with delta islands in 7e6de2ac628 (pack-objects: support `--delta-islands` with `--path-walk`, 2026-06-21), but that option only exposed an existing failure within the marking algorithm. At least one of the new tests exposes a failure without --path-walk. The issue is not just about different path names, but about appearing at paths of different depth. For example, a tree appearing at a/b/ can be visited with one set of marks as supplied from the trees at a/ while later being seen at x/y/z/ with different marks supplied by objects at x/y/. To fix this issue, we need to potentially reprocess a tree and everything it can reach when we discover an update to the delta island marks. This can lead to massive recomputation with certain data shapes that revisit objects from different paths. This seems unlikely to happen often in realistic scenarios, but is unavoidable without topologically sorting the entire object graph before distributing marks. Concretely, update set_island_marks() to report whether the object gained any bits in the process. Use a depth-priority queue to revisit trees that have new marks. We need to be careful to avoid adding duplicates to the queue without replicating the SEEN bit. This depth heuristic is only to prioritize a breadth-first-search, handling root trees before the next set of trees, and so on. This is intended to maximize the possibility of seeing all links to an object before visiting that object. The first-seen-depth problem was identified during the original delta-island review [1]: SEEN prevents revisiting shared trees, so their recorded depths need not give a topological ordering. That discussion illustrated missed delta opportunities. Incomplete marks can also allow unwanted cross-island deltas, as acknowledged for a related root-depth bug in 3949053617 (pack-objects: fix off-by-one in delta-island tree-depth computation, 2018-11-20) [2]. Later discussion emphasized real fork-network results and the difficulty of constructing focused corner-case tests [3]. [1] https://lore.kernel.org/git/20180727130229.GB18599@sigill.intra.peff.net/ [2] https://lore.kernel.org/git/20181120095053.GC22742@sigill.intra.peff.net/ [3] https://lore.kernel.org/git/20181120113423.GA29319@sigill.intra.peff.net/ Using p5305's historical-fork island selection, with --no-path-walk, bitmap reads disabled, --window=0, --compression=0, and stored deltas reusable, gives these old-to-fixed command times and tree visits: Time (s) Tree visits git/git 8.08 -> 8.24 162,791 -> 162,795 nodejs/node 9.85 -> 10.14 238,723 -> 239,837 microsoft/fluentui 4.13 -> 4.24 287,056 -> 287,136 torvalds/linux 176.28 -> 170.73 6,888,020 -> 6,888,085 It's possible that a true integration of delta islands with path-walk would help here, having the path-walk API compute the delta island marks as we traverse objects in path-based groups. Such an implementation would need to allow for objects to be readded to groups when their delta marks are updated while avoiding multiple emissions of the object from the API. Such a large rework of the delta island computation is avoided for now, as we can reproduce the error with the existing implementation. Assisted-by: GPT-6.1 Sol Signed-off-by: Derrick Stolee --- delta-islands: revisit trees with new delta marks Discovered while working on a real application of delta islands and the --path-walk feature. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2343%2Fderrickstolee%2Fdelta-islands-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2343/derrickstolee/delta-islands-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/2343 delta-islands.c | 63 +++++++++++++++++++--------- t/t5320-delta-islands.sh | 91 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 20 deletions(-) diff --git a/delta-islands.c b/delta-islands.c index c1c0f992f5..840484a4bc 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -10,6 +10,7 @@ #include "pack.h" #include "tree-walk.h" #include "diff.h" +#include "prio-queue.h" #include "progress.h" #include "refs.h" #include "khash.h" @@ -158,7 +159,7 @@ static struct island_bitmap *create_or_get_island_marks(struct object *obj) return kh_value(island_marks, pos); } -static void set_island_marks(struct object *obj, struct island_bitmap *marks) +static int set_island_marks(struct object *obj, struct island_bitmap *marks) { struct island_bitmap *b; khiter_t pos; @@ -172,19 +173,23 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks) */ marks->refcount++; kh_value(island_marks, pos) = marks; - return; + return 1; } + b = kh_value(island_marks, pos); + if (island_bitmap_is_subset(marks, b)) + return 0; + /* * We do have it. Make sure we split any copy-on-write before * updating. */ - b = kh_value(island_marks, pos); if (b->refcount > 1) { b->refcount--; b = kh_value(island_marks, pos) = island_bitmap_new(b); } island_bitmap_or(b, marks); + return 1; } static void mark_remote_island_1(struct repository *r, @@ -226,9 +231,10 @@ static void mark_remote_island_1(struct repository *r, struct tree_islands_todo { struct object_entry *entry; unsigned int depth; + unsigned queued:1; }; -static int tree_depth_compare(const void *a, const void *b) +static int tree_depth_compare(const void *a, const void *b, void *data UNUSED) { const struct tree_islands_todo *todo_a = a; const struct tree_islands_todo *todo_b = b; @@ -242,40 +248,44 @@ void resolve_tree_islands(struct repository *r, { struct progress *progress_state = NULL; struct tree_islands_todo *todo; - int nr = 0; - int i; + struct tree_islands_todo *current; + struct prio_queue queue = { .compare = tree_depth_compare }; + uint64_t processed = 0; + uint32_t i; if (!island_marks) return; /* * We process only trees, as commits and tags have already been handled - * (and passed their marks on to root trees, as well. We must make sure - * to process them in descending tree-depth order so that marks - * propagate down the tree properly, even if a sub-tree is found in - * multiple parent trees. + * (and passed their marks on to root trees, as well). Prefer shallower + * trees, but the first-seen depth can place a shared tree before + * another parent. Requeue trees whose marks change after processing. */ ALLOC_ARRAY(todo, to_pack->nr_objects); for (i = 0; i < to_pack->nr_objects; i++) { if (oe_type(&to_pack->objects[i]) == OBJ_TREE) { - todo[nr].entry = &to_pack->objects[i]; - todo[nr].depth = oe_tree_depth(to_pack, &to_pack->objects[i]); - nr++; + todo[i].entry = &to_pack->objects[i]; + todo[i].depth = oe_tree_depth(to_pack, &to_pack->objects[i]); + todo[i].queued = 1; + prio_queue_put(&queue, &todo[i]); } } - QSORT(todo, nr, tree_depth_compare); if (progress) - progress_state = start_progress(r, _("Propagating island marks"), nr); + progress_state = start_progress(r, _("Propagating island marks"), 0); - for (i = 0; i < nr; i++) { - struct object_entry *ent = todo[i].entry; + while ((current = prio_queue_get(&queue))) { + struct object_entry *ent = current->entry; struct island_bitmap *root_marks; struct tree *tree; struct tree_desc desc; struct name_entry entry; khiter_t pos; + current->queued = 0; + display_progress(progress_state, ++processed); + pos = kh_get_oid_map(island_marks, ent->idx.oid); if (pos >= kh_end(island_marks)) continue; @@ -289,6 +299,8 @@ void resolve_tree_islands(struct repository *r, init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { struct object *obj; + struct object_entry *child; + struct tree_islands_todo *child_todo; if (S_ISGITLINK(entry.mode)) continue; @@ -297,15 +309,26 @@ void resolve_tree_islands(struct repository *r, if (!obj) continue; - set_island_marks(obj, root_marks); + if (!set_island_marks(obj, root_marks) || + !S_ISDIR(entry.mode)) + continue; + + child = packlist_find(to_pack, &entry.oid); + if (!child || oe_type(child) != OBJ_TREE) + continue; + + child_todo = &todo[child - to_pack->objects]; + if (!child_todo->queued) { + child_todo->queued = 1; + prio_queue_put(&queue, child_todo); + } } free_tree_buffer(tree); - - display_progress(progress_state, i+1); } stop_progress(&progress_state); + clear_prio_queue(&queue); free(todo); } diff --git a/t/t5320-delta-islands.sh b/t/t5320-delta-islands.sh index 9b28344a0a..e8544cdfe3 100755 --- a/t/t5320-delta-islands.sh +++ b/t/t5320-delta-islands.sh @@ -170,4 +170,95 @@ test_expect_success 'unmatched island core is not fatal' ' git -c "pack.islandcore=one" repack -adfi ' +for order in deep-newer shallow-newer +do + test_expect_success "setup shared subtree ($order)" ' + git init "shared-subtree-$order" && + ( + cd "shared-subtree-$order" && + shared=$({ test-tool genrandom seed 10240 && echo 1; } | + git hash-object -w --stdin) && + private=$({ test-tool genrandom seed 10240 && echo 12; } | + git hash-object -w --stdin) && + nested=$({ test-tool genrandom nested 10240 && echo 1; } | + git hash-object -w --stdin) && + private_nested=$({ test-tool genrandom nested 10240 && echo 12; } | + git hash-object -w --stdin) && + leaf=$(printf "100644 blob %s\tfile\n" "$nested" | + git mktree) && + subtree=$(printf "040000 tree %s\tchild\n100644 blob %s\tfile\n" \ + "$leaf" "$shared" | git mktree) && + root_one=$({ + printf "040000 tree %s\ta\n" "$subtree" && + printf "100644 blob %s\tprivate\n" "$private" && + printf "100644 blob %s\tprivate-nested\n" "$private_nested" + } | git mktree) && + inner=$(printf "040000 tree %s\tc\n" "$subtree" | + git mktree) && + middle=$(printf "040000 tree %s\tb\n" "$inner" | + git mktree) && + root_two=$(printf "040000 tree %s\tz\n" "$middle" | + git mktree) && + test_tick && + one=$(echo one | git commit-tree "$root_one") && + test_tick && + two=$(echo two | git commit-tree "$root_two") && + if test "$order" = shallow-newer + then + test_tick && + one=$(echo one | git commit-tree "$root_one") + fi && + git update-ref refs/heads/one "$one" && + git update-ref refs/heads/two "$two" + ) + ' + + for traversal in --no-path-walk --path-walk + do + for bitmap in --no-write-bitmap-index --write-bitmap-index + do + test_expect_success "islands respect shared subtree ($order, $traversal, $bitmap)" ' + ( + cd "shared-subtree-$order" && + shared=$(git rev-parse one:a/file) && + nested=$(git rev-parse one:a/child/file) && + : >trace && + GIT_TRACE2_EVENT="$(pwd)/trace" \ + git -c "pack.island=refs/heads/(.*)" \ + repack -adfi "$bitmap" "$traversal" 2>err && + test_grep ! "failed to pack objects via path-walk" err && + if test "$traversal" = --path-walk + then + test_region pack-objects path-walk trace + fi && + is_delta_base "$shared" "$ZERO_OID" && + is_delta_base "$nested" "$ZERO_OID" + ) + ' + done + + test_expect_success "island core orders shared subtree ($order, $traversal)" ' + ( + cd "shared-subtree-$order" && + shared=$(git rev-parse one:a/file) && + private=$(git rev-parse one:private) && + : >trace && + GIT_TRACE2_EVENT="$(pwd)/trace" \ + git -c "pack.island=refs/heads/(.*)" \ + -c pack.islandCore=two repack -adfi "$traversal" 2>err && + test_grep ! "failed to pack objects via path-walk" err && + if test "$traversal" = --path-walk + then + test_region pack-objects path-walk trace + fi && + printf "%s\n" "$shared" "$private" >expect && + git verify-pack -v .git/objects/pack/*.pack >pack && + cut -d" " -f1 pack | + grep -E "^($shared|$private)$" >actual && + test_cmp expect actual + ) + ' + done +done + test_done base-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0 -- gitgitgadget