{"thread":{"id":"66962","subject":"[PATCH] delta-islands: revisit trees with new delta marks","startedAt":"2026-11-30T19:25:35Z","lastAt":"2026-12-02T19:53:01Z","messageCount":3,"participants":["Derrick Stolee via GitGitGadget","Elijah Newren","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559735","messageId":"pull.2343.git.1796066735611.gitgitgadget@gmail.com","threadId":"66962","inReplyTo":null,"subject":"[PATCH] delta-islands: revisit trees with new delta marks","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-30T19:25:35Z","receivedAt":"2026-11-30T19:25:35Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"From: Derrick Stolee <stolee@gmail.com>\n\nWhen exploring the object graph to group objects into delta-islands,\nsome trees and blobs can be visited from one path and then revisited\nlater from another. If those two visits come from objects with different\ndelta marks, then the final mark of the visited object should be the\nunion of those marks. Instead, some cases only have the first marks as\nwe don't reprocess objects marked with SEEN. This gets worse for objects\nrecursively reachable from that object.\n\nThis change includes some test cases that demonstrate this problem, and\nseveral of the modes fail without the accompanying code change. These\nexamples were discovered while working with the --path-walk option as\nintegrated with delta islands in 7e6de2ac628 (pack-objects: support\n`--delta-islands` with `--path-walk`, 2026-06-21), but that option only\nexposed an existing failure within the marking algorithm. At least\none of the new tests exposes a failure without --path-walk.\n\nThe issue is not just about different path names, but about appearing at\npaths of different depth. For example, a tree appearing at a/b/ can be\nvisited with one set of marks as supplied from the trees at a/ while\nlater being seen at x/y/z/ with different marks supplied by objects at\nx/y/.\n\nTo fix this issue, we need to potentially reprocess a tree and\neverything it can reach when we discover an update to the delta island\nmarks. This can lead to massive recomputation with certain data shapes\nthat revisit objects from different paths. This seems unlikely to happen\noften in realistic scenarios, but is unavoidable without topologically\nsorting the entire object graph before distributing marks.\n\nConcretely, update set_island_marks() to report whether the object\ngained any bits in the process. Use a depth-priority queue to revisit\ntrees that have new marks. We need to be careful to avoid adding\nduplicates to the queue without replicating the SEEN bit. This depth\nheuristic is only to prioritize a breadth-first-search, handling root\ntrees before the next set of trees, and so on. This is intended to\nmaximize the possibility of seeing all links to an object before\nvisiting that object.\n\nThe first-seen-depth problem was identified during the original\ndelta-island review [1]: SEEN prevents revisiting shared trees, so their\nrecorded depths need not give a topological ordering. That discussion\nillustrated missed delta opportunities. Incomplete marks can also allow\nunwanted cross-island deltas, as acknowledged for a related root-depth\nbug in 3949053617 (pack-objects: fix off-by-one in delta-island\ntree-depth computation, 2018-11-20) [2]. Later discussion emphasized\nreal fork-network results and the difficulty of constructing focused\ncorner-case tests [3].\n\n[1] https://lore.kernel.org/git/20180727130229.GB18599@sigill.intra.peff.net/\n[2] https://lore.kernel.org/git/20181120095053.GC22742@sigill.intra.peff.net/\n[3] https://lore.kernel.org/git/20181120113423.GA29319@sigill.intra.peff.net/\n\nUsing p5305's historical-fork island selection, with --no-path-walk,\nbitmap reads disabled, --window=0, --compression=0, and stored deltas\nreusable, gives these old-to-fixed command times and tree visits:\n\n                           Time (s)           Tree visits\n    git/git              8.08 ->   8.24      162,791 ->   162,795\n    nodejs/node          9.85 ->  10.14      238,723 ->   239,837\n    microsoft/fluentui   4.13 ->   4.24      287,056 ->   287,136\n    torvalds/linux     176.28 -> 170.73    6,888,020 -> 6,888,085\n\nIt's possible that a true integration of delta islands with path-walk\nwould help here, having the path-walk API compute the delta island marks\nas we traverse objects in path-based groups. Such an implementation\nwould need to allow for objects to be readded to groups when their delta\nmarks are updated while avoiding multiple emissions of the object from\nthe API. Such a large rework of the delta island computation is avoided\nfor now, as we can reproduce the error with the existing implementation.\n\nAssisted-by: GPT-6.1 Sol\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n    delta-islands: revisit trees with new delta marks\n    \n    Discovered while working on a real application of delta islands and the\n    --path-walk feature.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2343%2Fderrickstolee%2Fdelta-islands-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2343/derrickstolee/delta-islands-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2343\n\n delta-islands.c          | 63 +++++++++++++++++++---------\n t/t5320-delta-islands.sh | 91 ++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 134 insertions(+), 20 deletions(-)\n\ndiff --git a/delta-islands.c b/delta-islands.c\nindex c1c0f992f5..840484a4bc 100644\n--- a/delta-islands.c\n+++ b/delta-islands.c\n@@ -10,6 +10,7 @@\n #include \"pack.h\"\n #include \"tree-walk.h\"\n #include \"diff.h\"\n+#include \"prio-queue.h\"\n #include \"progress.h\"\n #include \"refs.h\"\n #include \"khash.h\"\n@@ -158,7 +159,7 @@ static struct island_bitmap *create_or_get_island_marks(struct object *obj)\n \treturn kh_value(island_marks, pos);\n }\n \n-static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n+static int set_island_marks(struct object *obj, struct island_bitmap *marks)\n {\n \tstruct island_bitmap *b;\n \tkhiter_t pos;\n@@ -172,19 +173,23 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n \t\t */\n \t\tmarks->refcount++;\n \t\tkh_value(island_marks, pos) = marks;\n-\t\treturn;\n+\t\treturn 1;\n \t}\n \n+\tb = kh_value(island_marks, pos);\n+\tif (island_bitmap_is_subset(marks, b))\n+\t\treturn 0;\n+\n \t/*\n \t * We do have it. Make sure we split any copy-on-write before\n \t * updating.\n \t */\n-\tb = kh_value(island_marks, pos);\n \tif (b->refcount > 1) {\n \t\tb->refcount--;\n \t\tb = kh_value(island_marks, pos) = island_bitmap_new(b);\n \t}\n \tisland_bitmap_or(b, marks);\n+\treturn 1;\n }\n \n static void mark_remote_island_1(struct repository *r,\n@@ -226,9 +231,10 @@ static void mark_remote_island_1(struct repository *r,\n struct tree_islands_todo {\n \tstruct object_entry *entry;\n \tunsigned int depth;\n+\tunsigned queued:1;\n };\n \n-static int tree_depth_compare(const void *a, const void *b)\n+static int tree_depth_compare(const void *a, const void *b, void *data UNUSED)\n {\n \tconst struct tree_islands_todo *todo_a = a;\n \tconst struct tree_islands_todo *todo_b = b;\n@@ -242,40 +248,44 @@ void resolve_tree_islands(struct repository *r,\n {\n \tstruct progress *progress_state = NULL;\n \tstruct tree_islands_todo *todo;\n-\tint nr = 0;\n-\tint i;\n+\tstruct tree_islands_todo *current;\n+\tstruct prio_queue queue = { .compare = tree_depth_compare };\n+\tuint64_t processed = 0;\n+\tuint32_t i;\n \n \tif (!island_marks)\n \t\treturn;\n \n \t/*\n \t * We process only trees, as commits and tags have already been handled\n-\t * (and passed their marks on to root trees, as well. We must make sure\n-\t * to process them in descending tree-depth order so that marks\n-\t * propagate down the tree properly, even if a sub-tree is found in\n-\t * multiple parent trees.\n+\t * (and passed their marks on to root trees, as well). Prefer shallower\n+\t * trees, but the first-seen depth can place a shared tree before\n+\t * another parent. Requeue trees whose marks change after processing.\n \t */\n \tALLOC_ARRAY(todo, to_pack->nr_objects);\n \tfor (i = 0; i < to_pack->nr_objects; i++) {\n \t\tif (oe_type(&to_pack->objects[i]) == OBJ_TREE) {\n-\t\t\ttodo[nr].entry = &to_pack->objects[i];\n-\t\t\ttodo[nr].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);\n-\t\t\tnr++;\n+\t\t\ttodo[i].entry = &to_pack->objects[i];\n+\t\t\ttodo[i].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);\n+\t\t\ttodo[i].queued = 1;\n+\t\t\tprio_queue_put(&queue, &todo[i]);\n \t\t}\n \t}\n-\tQSORT(todo, nr, tree_depth_compare);\n \n \tif (progress)\n-\t\tprogress_state = start_progress(r, _(\"Propagating island marks\"), nr);\n+\t\tprogress_state = start_progress(r, _(\"Propagating island marks\"), 0);\n \n-\tfor (i = 0; i < nr; i++) {\n-\t\tstruct object_entry *ent = todo[i].entry;\n+\twhile ((current = prio_queue_get(&queue))) {\n+\t\tstruct object_entry *ent = current->entry;\n \t\tstruct island_bitmap *root_marks;\n \t\tstruct tree *tree;\n \t\tstruct tree_desc desc;\n \t\tstruct name_entry entry;\n \t\tkhiter_t pos;\n \n+\t\tcurrent->queued = 0;\n+\t\tdisplay_progress(progress_state, ++processed);\n+\n \t\tpos = kh_get_oid_map(island_marks, ent->idx.oid);\n \t\tif (pos >= kh_end(island_marks))\n \t\t\tcontinue;\n@@ -289,6 +299,8 @@ void resolve_tree_islands(struct repository *r,\n \t\tinit_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);\n \t\twhile (tree_entry(&desc, &entry)) {\n \t\t\tstruct object *obj;\n+\t\t\tstruct object_entry *child;\n+\t\t\tstruct tree_islands_todo *child_todo;\n \n \t\t\tif (S_ISGITLINK(entry.mode))\n \t\t\t\tcontinue;\n@@ -297,15 +309,26 @@ void resolve_tree_islands(struct repository *r,\n \t\t\tif (!obj)\n \t\t\t\tcontinue;\n \n-\t\t\tset_island_marks(obj, root_marks);\n+\t\t\tif (!set_island_marks(obj, root_marks) ||\n+\t\t\t    !S_ISDIR(entry.mode))\n+\t\t\t\tcontinue;\n+\n+\t\t\tchild = packlist_find(to_pack, &entry.oid);\n+\t\t\tif (!child || oe_type(child) != OBJ_TREE)\n+\t\t\t\tcontinue;\n+\n+\t\t\tchild_todo = &todo[child - to_pack->objects];\n+\t\t\tif (!child_todo->queued) {\n+\t\t\t\tchild_todo->queued = 1;\n+\t\t\t\tprio_queue_put(&queue, child_todo);\n+\t\t\t}\n \t\t}\n \n \t\tfree_tree_buffer(tree);\n-\n-\t\tdisplay_progress(progress_state, i+1);\n \t}\n \n \tstop_progress(&progress_state);\n+\tclear_prio_queue(&queue);\n \tfree(todo);\n }\n \ndiff --git a/t/t5320-delta-islands.sh b/t/t5320-delta-islands.sh\nindex 9b28344a0a..e8544cdfe3 100755\n--- a/t/t5320-delta-islands.sh\n+++ b/t/t5320-delta-islands.sh\n@@ -170,4 +170,95 @@ test_expect_success 'unmatched island core is not fatal' '\n \tgit -c \"pack.islandcore=one\" repack -adfi\n '\n \n+for order in deep-newer shallow-newer\n+do\n+\ttest_expect_success \"setup shared subtree ($order)\" '\n+\t\tgit init \"shared-subtree-$order\" &&\n+\t\t(\n+\t\t\tcd \"shared-subtree-$order\" &&\n+\t\t\tshared=$({ test-tool genrandom seed 10240 && echo 1; } |\n+\t\t\t\tgit hash-object -w --stdin) &&\n+\t\t\tprivate=$({ test-tool genrandom seed 10240 && echo 12; } |\n+\t\t\t\tgit hash-object -w --stdin) &&\n+\t\t\tnested=$({ test-tool genrandom nested 10240 && echo 1; } |\n+\t\t\t\tgit hash-object -w --stdin) &&\n+\t\t\tprivate_nested=$({ test-tool genrandom nested 10240 && echo 12; } |\n+\t\t\t\tgit hash-object -w --stdin) &&\n+\t\t\tleaf=$(printf \"100644 blob %s\\tfile\\n\" \"$nested\" |\n+\t\t\t\tgit mktree) &&\n+\t\t\tsubtree=$(printf \"040000 tree %s\\tchild\\n100644 blob %s\\tfile\\n\" \\\n+\t\t\t\t\"$leaf\" \"$shared\" | git mktree) &&\n+\t\t\troot_one=$({\n+\t\t\t\tprintf \"040000 tree %s\\ta\\n\" \"$subtree\" &&\n+\t\t\t\tprintf \"100644 blob %s\\tprivate\\n\" \"$private\" &&\n+\t\t\t\tprintf \"100644 blob %s\\tprivate-nested\\n\" \"$private_nested\"\n+\t\t\t} | git mktree) &&\n+\t\t\tinner=$(printf \"040000 tree %s\\tc\\n\" \"$subtree\" |\n+\t\t\t\tgit mktree) &&\n+\t\t\tmiddle=$(printf \"040000 tree %s\\tb\\n\" \"$inner\" |\n+\t\t\t\tgit mktree) &&\n+\t\t\troot_two=$(printf \"040000 tree %s\\tz\\n\" \"$middle\" |\n+\t\t\t\tgit mktree) &&\n+\t\t\ttest_tick &&\n+\t\t\tone=$(echo one | git commit-tree \"$root_one\") &&\n+\t\t\ttest_tick &&\n+\t\t\ttwo=$(echo two | git commit-tree \"$root_two\") &&\n+\t\t\tif test \"$order\" = shallow-newer\n+\t\t\tthen\n+\t\t\t\ttest_tick &&\n+\t\t\t\tone=$(echo one | git commit-tree \"$root_one\")\n+\t\t\tfi &&\n+\t\t\tgit update-ref refs/heads/one \"$one\" &&\n+\t\t\tgit update-ref refs/heads/two \"$two\"\n+\t\t)\n+\t'\n+\n+\tfor traversal in --no-path-walk --path-walk\n+\tdo\n+\t\tfor bitmap in --no-write-bitmap-index --write-bitmap-index\n+\t\tdo\n+\t\t\ttest_expect_success \"islands respect shared subtree ($order, $traversal, $bitmap)\" '\n+\t\t\t\t(\n+\t\t\t\t\tcd \"shared-subtree-$order\" &&\n+\t\t\t\t\tshared=$(git rev-parse one:a/file) &&\n+\t\t\t\t\tnested=$(git rev-parse one:a/child/file) &&\n+\t\t\t\t\t: >trace &&\n+\t\t\t\t\tGIT_TRACE2_EVENT=\"$(pwd)/trace\" \\\n+\t\t\t\t\tgit -c \"pack.island=refs/heads/(.*)\" \\\n+\t\t\t\t\t\trepack -adfi \"$bitmap\" \"$traversal\" 2>err &&\n+\t\t\t\t\ttest_grep ! \"failed to pack objects via path-walk\" err &&\n+\t\t\t\t\tif test \"$traversal\" = --path-walk\n+\t\t\t\t\tthen\n+\t\t\t\t\t\ttest_region pack-objects path-walk trace\n+\t\t\t\t\tfi &&\n+\t\t\t\t\tis_delta_base \"$shared\" \"$ZERO_OID\" &&\n+\t\t\t\t\tis_delta_base \"$nested\" \"$ZERO_OID\"\n+\t\t\t\t)\n+\t\t\t'\n+\t\tdone\n+\n+\t\ttest_expect_success \"island core orders shared subtree ($order, $traversal)\" '\n+\t\t\t(\n+\t\t\t\tcd \"shared-subtree-$order\" &&\n+\t\t\t\tshared=$(git rev-parse one:a/file) &&\n+\t\t\t\tprivate=$(git rev-parse one:private) &&\n+\t\t\t\t: >trace &&\n+\t\t\t\tGIT_TRACE2_EVENT=\"$(pwd)/trace\" \\\n+\t\t\t\tgit -c \"pack.island=refs/heads/(.*)\" \\\n+\t\t\t\t\t-c pack.islandCore=two repack -adfi \"$traversal\" 2>err &&\n+\t\t\t\ttest_grep ! \"failed to pack objects via path-walk\" err &&\n+\t\t\t\tif test \"$traversal\" = --path-walk\n+\t\t\t\tthen\n+\t\t\t\t\ttest_region pack-objects path-walk trace\n+\t\t\t\tfi &&\n+\t\t\t\tprintf \"%s\\n\" \"$shared\" \"$private\" >expect &&\n+\t\t\t\tgit verify-pack -v .git/objects/pack/*.pack >pack &&\n+\t\t\t\tcut -d\" \" -f1 pack |\n+\t\t\t\tgrep -E \"^($shared|$private)$\" >actual &&\n+\t\t\t\ttest_cmp expect actual\n+\t\t\t)\n+\t\t'\n+\tdone\n+done\n+\n test_done\n\nbase-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0\n-- \ngitgitgadget\n\n"},{"id":"559907","messageId":"CABPp-BEzyAq6a=uq9-sOsAXFYjHdrga99+QauGxbkkTnOjLaGw@mail.gmail.com","threadId":"66962","inReplyTo":"pull.2343.git.1796066735611.gitgitgadget@gmail.com","subject":"Re: [PATCH] delta-islands: revisit trees with new delta marks","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2026-12-02T19:14:12Z","receivedAt":"2026-12-02T19:14:12Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Mon, Nov 30, 2026 at 11:25 AM Derrick Stolee via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Derrick Stolee <stolee@gmail.com>\n>\n> When exploring the object graph to group objects into delta-islands,\n> some trees and blobs can be visited from one path and then revisited\n> later from another. If those two visits come from objects with different\n> delta marks, then the final mark of the visited object should be the\n> union of those marks. Instead, some cases only have the first marks as\n> we don't reprocess objects marked with SEEN. This gets worse for objects\n> recursively reachable from that object.\n>\n> This change includes some test cases that demonstrate this problem, and\n> several of the modes fail without the accompanying code change. These\n> examples were discovered while working with the --path-walk option as\n> integrated with delta islands in 7e6de2ac628 (pack-objects: support\n> `--delta-islands` with `--path-walk`, 2026-06-21), but that option only\n> exposed an existing failure within the marking algorithm. At least\n> one of the new tests exposes a failure without --path-walk.\n>\n> The issue is not just about different path names, but about appearing at\n> paths of different depth. For example, a tree appearing at a/b/ can be\n> visited with one set of marks as supplied from the trees at a/ while\n> later being seen at x/y/z/ with different marks supplied by objects at\n> x/y/.\n>\n> To fix this issue, we need to potentially reprocess a tree and\n> everything it can reach when we discover an update to the delta island\n> marks. This can lead to massive recomputation with certain data shapes\n> that revisit objects from different paths. This seems unlikely to happen\n> often in realistic scenarios, but is unavoidable without topologically\n> sorting the entire object graph before distributing marks.\n>\n> Concretely, update set_island_marks() to report whether the object\n> gained any bits in the process. Use a depth-priority queue to revisit\n> trees that have new marks. We need to be careful to avoid adding\n> duplicates to the queue without replicating the SEEN bit. This depth\n> heuristic is only to prioritize a breadth-first-search, handling root\n> trees before the next set of trees, and so on. This is intended to\n> maximize the possibility of seeing all links to an object before\n> visiting that object.\n>\n> The first-seen-depth problem was identified during the original\n> delta-island review [1]: SEEN prevents revisiting shared trees, so their\n> recorded depths need not give a topological ordering. That discussion\n> illustrated missed delta opportunities. Incomplete marks can also allow\n> unwanted cross-island deltas, as acknowledged for a related root-depth\n> bug in 3949053617 (pack-objects: fix off-by-one in delta-island\n> tree-depth computation, 2018-11-20) [2]. Later discussion emphasized\n> real fork-network results and the difficulty of constructing focused\n> corner-case tests [3].\n>\n> [1] https://lore.kernel.org/git/20180727130229.GB18599@sigill.intra.peff.net/\n> [2] https://lore.kernel.org/git/20181120095053.GC22742@sigill.intra.peff.net/\n> [3] https://lore.kernel.org/git/20181120113423.GA29319@sigill.intra.peff.net/\n>\n> Using p5305's historical-fork island selection, with --no-path-walk,\n> bitmap reads disabled, --window=0, --compression=0, and stored deltas\n> reusable, gives these old-to-fixed command times and tree visits:\n>\n>                            Time (s)           Tree visits\n>     git/git              8.08 ->   8.24      162,791 ->   162,795\n>     nodejs/node          9.85 ->  10.14      238,723 ->   239,837\n>     microsoft/fluentui   4.13 ->   4.24      287,056 ->   287,136\n>     torvalds/linux     176.28 -> 170.73    6,888,020 -> 6,888,085\n>\n> It's possible that a true integration of delta islands with path-walk\n> would help here, having the path-walk API compute the delta island marks\n> as we traverse objects in path-based groups. Such an implementation\n> would need to allow for objects to be readded to groups when their delta\n> marks are updated while avoiding multiple emissions of the object from\n> the API. Such a large rework of the delta island computation is avoided\n> for now, as we can reproduce the error with the existing implementation.\n\nI had difficulty discerning the impact and motivation of the bug you\nare trying to fix, possibly because I only know a little about delta\nislands.  There is one paragraph that states it (\"unwanted\ncross-island deltas\"), but it reads as history rather than motivation,\nso I missed it at first.  Would it make sense to include the\nmotivation near the top of the commit message?  I asked AI, and it\ntold me...\n\n```\nDelta islands ensure that an object is only stored as a delta against\na base that is reachable from every island containing the object, so\nthat serving any one fork can reuse the on-disk delta instead of\nbreaking it and searching for a new one on the fly.\n\nHowever, island marks can be incomplete. resolve_tree_islands()\npropagates each tree's marks to its children once, in order of the\ndepth at which the tree was first seen. A tree shared at different\ndepths (e.g. seen at a/b/ and at x/y/z/) can therefore have its marks\npropagated before a parent from another island adds to them, and the\nlate-arriving marks never reach the trees and blobs below it. An\nobject missing marks looks like it belongs to fewer islands, so it can\nbe deltified against a base that some of its islands cannot reach,\nreintroducing the expensive delta-breaking that islands exist to\nprevent. When the base is the one missing marks, valid deltas are\ninstead rejected, making packs larger.\n```\n\n>\n> Assisted-by: GPT-6.1 Sol\n> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>\n\nI think Signed-off-by is supposed to match the committer; you've used\ntwo different email addresses.\n\n> ---\n>     delta-islands: revisit trees with new delta marks\n>\n>     Discovered while working on a real application of delta islands and the\n>     --path-walk feature.\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2343%2Fderrickstolee%2Fdelta-islands-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2343/derrickstolee/delta-islands-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/2343\n>\n>  delta-islands.c          | 63 +++++++++++++++++++---------\n>  t/t5320-delta-islands.sh | 91 ++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 134 insertions(+), 20 deletions(-)\n>\n> diff --git a/delta-islands.c b/delta-islands.c\n> index c1c0f992f5..840484a4bc 100644\n> --- a/delta-islands.c\n> +++ b/delta-islands.c\n> @@ -10,6 +10,7 @@\n>  #include \"pack.h\"\n>  #include \"tree-walk.h\"\n>  #include \"diff.h\"\n> +#include \"prio-queue.h\"\n>  #include \"progress.h\"\n>  #include \"refs.h\"\n>  #include \"khash.h\"\n> @@ -158,7 +159,7 @@ static struct island_bitmap *create_or_get_island_marks(struct object *obj)\n>         return kh_value(island_marks, pos);\n>  }\n>\n> -static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n> +static int set_island_marks(struct object *obj, struct island_bitmap *marks)\n>  {\n>         struct island_bitmap *b;\n>         khiter_t pos;\n> @@ -172,19 +173,23 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n>                  */\n>                 marks->refcount++;\n>                 kh_value(island_marks, pos) = marks;\n> -               return;\n> +               return 1;\n>         }\n>\n> +       b = kh_value(island_marks, pos);\n> +       if (island_bitmap_is_subset(marks, b))\n> +               return 0;\n> +\n>         /*\n>          * We do have it. Make sure we split any copy-on-write before\n>          * updating.\n>          */\n> -       b = kh_value(island_marks, pos);\n>         if (b->refcount > 1) {\n>                 b->refcount--;\n>                 b = kh_value(island_marks, pos) = island_bitmap_new(b);\n>         }\n>         island_bitmap_or(b, marks);\n> +       return 1;\n>  }\n\nYou're now returning whether obj's marks changed.  Is it worth adding\na comment above the function mentioning the meaning of the return\nvalue?\n\n>  static void mark_remote_island_1(struct repository *r,\n> @@ -226,9 +231,10 @@ static void mark_remote_island_1(struct repository *r,\n>  struct tree_islands_todo {\n>         struct object_entry *entry;\n>         unsigned int depth;\n> +       unsigned queued:1;\n>  };\n>\n> -static int tree_depth_compare(const void *a, const void *b)\n> +static int tree_depth_compare(const void *a, const void *b, void *data UNUSED)\n>  {\n>         const struct tree_islands_todo *todo_a = a;\n>         const struct tree_islands_todo *todo_b = b;\n> @@ -242,40 +248,44 @@ void resolve_tree_islands(struct repository *r,\n>  {\n>         struct progress *progress_state = NULL;\n>         struct tree_islands_todo *todo;\n> -       int nr = 0;\n> -       int i;\n> +       struct tree_islands_todo *current;\n> +       struct prio_queue queue = { .compare = tree_depth_compare };\n> +       uint64_t processed = 0;\n> +       uint32_t i;\n\nThis typechange on i fixes a signed/unsigned mismatch that previously\nexisted for comparing `i` to `to_pack->nr_objects`; nice.\n\n>\n>         if (!island_marks)\n>                 return;\n>\n>         /*\n>          * We process only trees, as commits and tags have already been handled\n> -        * (and passed their marks on to root trees, as well. We must make sure\n> -        * to process them in descending tree-depth order so that marks\n> -        * propagate down the tree properly, even if a sub-tree is found in\n> -        * multiple parent trees.\n> +        * (and passed their marks on to root trees, as well). Prefer shallower\n> +        * trees, but the first-seen depth can place a shared tree before\n> +        * another parent. Requeue trees whose marks change after processing.\n>          */\n>         ALLOC_ARRAY(todo, to_pack->nr_objects);\n>         for (i = 0; i < to_pack->nr_objects; i++) {\n>                 if (oe_type(&to_pack->objects[i]) == OBJ_TREE) {\n> -                       todo[nr].entry = &to_pack->objects[i];\n> -                       todo[nr].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);\n> -                       nr++;\n> +                       todo[i].entry = &to_pack->objects[i];\n> +                       todo[i].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);\n> +                       todo[i].queued = 1;\n> +                       prio_queue_put(&queue, &todo[i]);\n>                 }\n>         }\n> -       QSORT(todo, nr, tree_depth_compare);\n>\n>         if (progress)\n> -               progress_state = start_progress(r, _(\"Propagating island marks\"), nr);\n> +               progress_state = start_progress(r, _(\"Propagating island marks\"), 0);\n\nWe've changed from showing a percentage of completion to just a count\nof trees processed.  Since trees can be reprocessed, there's no\nreasonable total we can give, so this seems like a reasonable change.\nI'm curious if it's worth calling this out in the commit message.\n\n> -       for (i = 0; i < nr; i++) {\n> -               struct object_entry *ent = todo[i].entry;\n> +       while ((current = prio_queue_get(&queue))) {\n> +               struct object_entry *ent = current->entry;\n>                 struct island_bitmap *root_marks;\n>                 struct tree *tree;\n>                 struct tree_desc desc;\n>                 struct name_entry entry;\n>                 khiter_t pos;\n>\n> +               current->queued = 0;\n> +               display_progress(progress_state, ++processed);\n> +\n>                 pos = kh_get_oid_map(island_marks, ent->idx.oid);\n>                 if (pos >= kh_end(island_marks))\n>                         continue;\n> @@ -289,6 +299,8 @@ void resolve_tree_islands(struct repository *r,\n>                 init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);\n>                 while (tree_entry(&desc, &entry)) {\n>                         struct object *obj;\n> +                       struct object_entry *child;\n> +                       struct tree_islands_todo *child_todo;\n>\n>                         if (S_ISGITLINK(entry.mode))\n>                                 continue;\n> @@ -297,15 +309,26 @@ void resolve_tree_islands(struct repository *r,\n>                         if (!obj)\n>                                 continue;\n>\n> -                       set_island_marks(obj, root_marks);\n> +                       if (!set_island_marks(obj, root_marks) ||\n> +                           !S_ISDIR(entry.mode))\n> +                               continue;\n> +\n> +                       child = packlist_find(to_pack, &entry.oid);\n> +                       if (!child || oe_type(child) != OBJ_TREE)\n> +                               continue;\n> +\n> +                       child_todo = &todo[child - to_pack->objects];\n> +                       if (!child_todo->queued) {\n> +                               child_todo->queued = 1;\n> +                               prio_queue_put(&queue, child_todo);\n> +                       }\n>                 }\n>\n>                 free_tree_buffer(tree);\n> -\n> -               display_progress(progress_state, i+1);\n>         }\n>\n>         stop_progress(&progress_state);\n> +       clear_prio_queue(&queue);\n>         free(todo);\n>  }\n>\n> diff --git a/t/t5320-delta-islands.sh b/t/t5320-delta-islands.sh\n> index 9b28344a0a..e8544cdfe3 100755\n> --- a/t/t5320-delta-islands.sh\n> +++ b/t/t5320-delta-islands.sh\n> @@ -170,4 +170,95 @@ test_expect_success 'unmatched island core is not fatal' '\n>         git -c \"pack.islandcore=one\" repack -adfi\n>  '\n>\n> +for order in deep-newer shallow-newer\n> +do\n> +       test_expect_success \"setup shared subtree ($order)\" '\n> +               git init \"shared-subtree-$order\" &&\n> +               (\n> +                       cd \"shared-subtree-$order\" &&\n> +                       shared=$({ test-tool genrandom seed 10240 && echo 1; } |\n> +                               git hash-object -w --stdin) &&\n> +                       private=$({ test-tool genrandom seed 10240 && echo 12; } |\n> +                               git hash-object -w --stdin) &&\n> +                       nested=$({ test-tool genrandom nested 10240 && echo 1; } |\n> +                               git hash-object -w --stdin) &&\n> +                       private_nested=$({ test-tool genrandom nested 10240 && echo 12; } |\n> +                               git hash-object -w --stdin) &&\n> +                       leaf=$(printf \"100644 blob %s\\tfile\\n\" \"$nested\" |\n> +                               git mktree) &&\n> +                       subtree=$(printf \"040000 tree %s\\tchild\\n100644 blob %s\\tfile\\n\" \\\n> +                               \"$leaf\" \"$shared\" | git mktree) &&\n> +                       root_one=$({\n> +                               printf \"040000 tree %s\\ta\\n\" \"$subtree\" &&\n> +                               printf \"100644 blob %s\\tprivate\\n\" \"$private\" &&\n> +                               printf \"100644 blob %s\\tprivate-nested\\n\" \"$private_nested\"\n> +                       } | git mktree) &&\n> +                       inner=$(printf \"040000 tree %s\\tc\\n\" \"$subtree\" |\n> +                               git mktree) &&\n> +                       middle=$(printf \"040000 tree %s\\tb\\n\" \"$inner\" |\n> +                               git mktree) &&\n> +                       root_two=$(printf \"040000 tree %s\\tz\\n\" \"$middle\" |\n> +                               git mktree) &&\n> +                       test_tick &&\n> +                       one=$(echo one | git commit-tree \"$root_one\") &&\n> +                       test_tick &&\n> +                       two=$(echo two | git commit-tree \"$root_two\") &&\n> +                       if test \"$order\" = shallow-newer\n> +                       then\n> +                               test_tick &&\n> +                               one=$(echo one | git commit-tree \"$root_one\")\n> +                       fi &&\n> +                       git update-ref refs/heads/one \"$one\" &&\n> +                       git update-ref refs/heads/two \"$two\"\n> +               )\n> +       '\n> +\n> +       for traversal in --no-path-walk --path-walk\n> +       do\n> +               for bitmap in --no-write-bitmap-index --write-bitmap-index\n> +               do\n> +                       test_expect_success \"islands respect shared subtree ($order, $traversal, $bitmap)\" '\n> +                               (\n> +                                       cd \"shared-subtree-$order\" &&\n> +                                       shared=$(git rev-parse one:a/file) &&\n> +                                       nested=$(git rev-parse one:a/child/file) &&\n> +                                       : >trace &&\n> +                                       GIT_TRACE2_EVENT=\"$(pwd)/trace\" \\\n> +                                       git -c \"pack.island=refs/heads/(.*)\" \\\n> +                                               repack -adfi \"$bitmap\" \"$traversal\" 2>err &&\n> +                                       test_grep ! \"failed to pack objects via path-walk\" err &&\n> +                                       if test \"$traversal\" = --path-walk\n> +                                       then\n> +                                               test_region pack-objects path-walk trace\n> +                                       fi &&\n> +                                       is_delta_base \"$shared\" \"$ZERO_OID\" &&\n> +                                       is_delta_base \"$nested\" \"$ZERO_OID\"\n> +                               )\n> +                       '\n> +               done\n> +\n> +               test_expect_success \"island core orders shared subtree ($order, $traversal)\" '\n> +                       (\n> +                               cd \"shared-subtree-$order\" &&\n> +                               shared=$(git rev-parse one:a/file) &&\n> +                               private=$(git rev-parse one:private) &&\n> +                               : >trace &&\n> +                               GIT_TRACE2_EVENT=\"$(pwd)/trace\" \\\n> +                               git -c \"pack.island=refs/heads/(.*)\" \\\n> +                                       -c pack.islandCore=two repack -adfi \"$traversal\" 2>err &&\n> +                               test_grep ! \"failed to pack objects via path-walk\" err &&\n> +                               if test \"$traversal\" = --path-walk\n> +                               then\n> +                                       test_region pack-objects path-walk trace\n> +                               fi &&\n> +                               printf \"%s\\n\" \"$shared\" \"$private\" >expect &&\n> +                               git verify-pack -v .git/objects/pack/*.pack >pack &&\n> +                               cut -d\" \" -f1 pack |\n> +                               grep -E \"^($shared|$private)$\" >actual &&\n> +                               test_cmp expect actual\n> +                       )\n> +               '\n> +       done\n> +done\n> +\n>  test_done\n>\n> base-commit: 7fb6055e678f800320d8ab8cd8f201d9493d1ba0\n> --\n> gitgitgadget\n\nLooks good.\n\n"},{"id":"559909","messageId":"6bcf9997-068e-45f3-b737-9df430671de1@gmail.com","threadId":"66962","inReplyTo":"CABPp-BEzyAq6a=uq9-sOsAXFYjHdrga99+QauGxbkkTnOjLaGw@mail.gmail.com","subject":"Re: [PATCH] delta-islands: revisit trees with new delta marks","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-12-02T19:53:01Z","receivedAt":"2026-12-02T19:53:01Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/2/2026 2:14 PM, Elijah Newren wrote:\n> On Mon, Nov 30, 2026 at 11:25 AM Derrick Stolee via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n>>\n>> From: Derrick Stolee <stolee@gmail.com>\n>>\n>> When exploring the object graph to group objects into delta-islands,\n>> some trees and blobs can be visited from one path and then revisited\n>> later from another. If those two visits come from objects with different\n>> delta marks, then the final mark of the visited object should be the\n>> union of those marks. Instead, some cases only have the first marks as\n>> we don't reprocess objects marked with SEEN. This gets worse for objects\n>> recursively reachable from that object.\n...\n>> It's possible that a true integration of delta islands with path-walk\n>> would help here, having the path-walk API compute the delta island marks\n>> as we traverse objects in path-based groups. Such an implementation\n>> would need to allow for objects to be readded to groups when their delta\n>> marks are updated while avoiding multiple emissions of the object from\n>> the API. Such a large rework of the delta island computation is avoided\n>> for now, as we can reproduce the error with the existing implementation.\n> \n> I had difficulty discerning the impact and motivation of the bug you\n> are trying to fix, possibly because I only know a little about delta\n> islands.  There is one paragraph that states it (\"unwanted\n> cross-island deltas\"), but it reads as history rather than motivation,\n> so I missed it at first.  Would it make sense to include the\n> motivation near the top of the commit message?  I asked AI, and it\n> told me...\n> \n> ```\n> Delta islands ensure that an object is only stored as a delta against\n> a base that is reachable from every island containing the object, so\n> that serving any one fork can reuse the on-disk delta instead of\n> breaking it and searching for a new one on the fly.\n> \n> However, island marks can be incomplete. resolve_tree_islands()\n> propagates each tree's marks to its children once, in order of the\n> depth at which the tree was first seen. A tree shared at different\n> depths (e.g. seen at a/b/ and at x/y/z/) can therefore have its marks\n> propagated before a parent from another island adds to them, and the\n> late-arriving marks never reach the trees and blobs below it. An\n> object missing marks looks like it belongs to fewer islands, so it can\n> be deltified against a base that some of its islands cannot reach,\n> reintroducing the expensive delta-breaking that islands exist to\n> prevent. When the base is the one missing marks, valid deltas are\n> instead rejected, making packs larger.\n> ```\n\nThe base motivation of using delta islands is about avoiding delta\nexpansion and recompression during clones and fetches. By grouping\ncertain tip commits into \"reachability categories\" (say, refs for\neach fork in a network) we can avoid having delta bases outside of\na typical clone in that \"category\".\n\nI think [1] is still the best description of this mechanism.\n\n[1] https://blog.github.com/open-source/git/counting-objects/#the-performance-fix\n\nThere might also be interesting cases where we say that a \"trunk\"\nref is a certain category and other branches are still reachable but\na different island. That could present improvements for --single-branch\nclones.\n\n>> Assisted-by: GPT-6.1 Sol\n>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>\n> \n> I think Signed-off-by is supposed to match the committer; you've used\n> two different email addresses.\n\nI noticed this in my submission and have prepared a version already with\nthe fix. I created this in the wrong local directory that had the wrong\nemail configured. Will fix in v2.\n\n>> -static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n>> +static int set_island_marks(struct object *obj, struct island_bitmap *marks)\n>>  {\n>>         struct island_bitmap *b;\n>>         khiter_t pos;\n>> @@ -172,19 +173,23 @@ static void set_island_marks(struct object *obj, struct island_bitmap *marks)\n>>                  */\n>>                 marks->refcount++;\n>>                 kh_value(island_marks, pos) = marks;\n>> -               return;\n>> +               return 1;\n>>         }\n>>\n>> +       b = kh_value(island_marks, pos);\n>> +       if (island_bitmap_is_subset(marks, b))\n>> +               return 0;\n>> +\n>>         /*\n>>          * We do have it. Make sure we split any copy-on-write before\n>>          * updating.\n>>          */\n>> -       b = kh_value(island_marks, pos);\n>>         if (b->refcount > 1) {\n>>                 b->refcount--;\n>>                 b = kh_value(island_marks, pos) = island_bitmap_new(b);\n>>         }\n>>         island_bitmap_or(b, marks);\n>> +       return 1;\n>>  }\n> \n> You're now returning whether obj's marks changed.  Is it worth adding\n> a comment above the function mentioning the meaning of the return\n> value?\n\nA doc-comment would be good now that this has a nonzero (non-error)\nreturn value.\n\n>>         if (progress)\n>> -               progress_state = start_progress(r, _(\"Propagating island marks\"), nr);\n>> +               progress_state = start_progress(r, _(\"Propagating island marks\"), 0);\n> \n> We've changed from showing a percentage of completion to just a count\n> of trees processed.  Since trees can be reprocessed, there's no\n> reasonable total we can give, so this seems like a reasonable change.\n> I'm curious if it's worth calling this out in the commit message.\n\nIt probably is. Can do.\n> Looks good.\n\nThanks for the review!\n-Stolee\n\n\n"}]}