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

[PATCH v2 23/24] pack-bitmap-write: relax unique rewalk condition

From
Taylor Blau <me@ttaylorr.com>
Date
Nov 17, 2020, 21:48 UTC
Message-ID
<1da4fa0fb85fe848aa86987e767b33d296f8f878.1605649533.git.me@ttaylorr.com>
In-Reply-To
<cover.1605649533.git.me@ttaylorr.com>
From: Derrick Stolee <dstolee@microsoft.com>

The previous commits improved the bitmap computation process for very long, linear histories with many refs by removing quadratic growth in how many objects were walked. The strategy of computing "intermediate commits" using bitmasks for which refs can reach those commits partitioned the poset of reachable objects so each part could be walked exactly once. This was effective for linear histories.

However, there was a (significant) drawback: wide histories with many refs had an explosion of memory costs to compute the commit bitmasks during the exploration that discovers these intermediate commits. Since these wide histories are unlikely to repeat walking objects, the benefit of walking objects multiple times was not expensive before. But now, the commit walk *before computing bitmaps* is incredibly expensive.

In an effort to discover a happy medium, this change reduces the walk for intermediate commits to only the first-parent history. This focuses the walk on how the histories converge, which still has significant reduction in repeat object walks. It is still possible to create quadratic behavior in this version, but it is probably less likely in realistic data shapes.

Here is some data taken on a fresh clone of the kernel:
             |   runtime (sec)    |   peak heap (GB)   |
             |                    |                    |
             |   from  |   with   |   from  |   with   |
             | scratch | existing | scratch | existing |
  -----------+---------+----------+---------+-----------
    original |  64.044 |   83.241 |   2.088 |    2.194 |
  last patch |  44.811 |   27.828 |   2.289 |    2.358 |
  this patch | 100.641 |   35.560 |   2.152 |    2.224 |
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap-write.c     | 14 +++++---------
 t/t5310-pack-bitmaps.sh | 27 ++++++++++++++-------------
 2 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37204b691c..b0493d971d 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -199,7 +199,7 @@ static void bitmap_builder_init(struct bitmap_builder *bb,
 {
 	struct rev_info revs;
 	struct commit *commit;
-	unsigned int i, num_maximal;
+	unsigned int i, num_maximal = 0;
 
 	memset(bb, 0, sizeof(*bb));
 	init_bb_data(&bb->data);
@@ -207,6 +207,7 @@ static void bitmap_builder_init(struct bitmap_builder *bb,
 	reset_revision_walk();
 	repo_init_revisions(writer->to_pack->repo, &revs, NULL);
 	revs.topo_order = 1;
+	revs.first_parent_only = 1;
 
 	for (i = 0; i < writer->selected_nr; i++) {
 		struct commit *c = writer->selected[i].commit;
@@ -221,13 +222,12 @@ static void bitmap_builder_init(struct bitmap_builder *bb,
 
 		add_pending_object(&revs, &c->object, "");
 	}
-	num_maximal = writer->selected_nr;
 
 	if (prepare_revision_walk(&revs))
 		die("revision walk setup failed");
 
 	while ((commit = get_revision(&revs))) {
-		struct commit_list *p;
+		struct commit_list *p = commit->parents;
 		struct bb_commit *c_ent;
 
 		parse_commit_or_die(commit);
@@ -235,16 +235,12 @@ static void bitmap_builder_init(struct bitmap_builder *bb,
 		c_ent = bb_data_at(&bb->data, commit);
 
 		if (c_ent->maximal) {
-			if (!c_ent->selected) {
-				bitmap_set(c_ent->commit_mask, num_maximal);
-				num_maximal++;
-			}
-
+			num_maximal++;
 			ALLOC_GROW(bb->commits, bb->commits_nr + 1, bb->commits_alloc);
 			bb->commits[bb->commits_nr++] = commit;
 		}
 
-		for (p = commit->parents; p; p = p->next) {
+		if (p) {
 			struct bb_commit *p_ent = bb_data_at(&bb->data, p->item);
 			int c_not_p, p_not_c;
 
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index 1691710ec1..a83e7a93fb 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -43,23 +43,24 @@ has_any () {
 #                                   \|
 #                                    * (base)
 #
+# We only push bits down the first-parent history, which
+# makes some of these commits unimportant!
+#
 # The important part for the maximal commit algorithm is how
 # the bitmasks are extended. Assuming starting bit positions
-# for master (bit 0) and other (bit 1), and some flexibility
-# in the order that merge bases are visited, the bitmasks at
-# the end should be:
+# for master (bit 0) and other (bit 1), the bitmasks at the
+# end should be:
 #
 #      master: 1       (maximal, selected)
 #       other: 01      (maximal, selected)
-# octo-master: 1
-#  octo-other: 01
-# merge-right: 111     (maximal)
-#        (l1): 111
-#        (r1): 111
-#  merge-left: 1101    (maximal)
-#        (l2): 11111   (maximal)
-#        (r2): 111101  (maximal)
-#      (base): 1111111 (maximal)
+#      (base): 11 (maximal)
+#
+# This complicated history was important for a previous
+# version of the walk that guarantees never walking a
+# commit multiple times. That goal might be important
+# again, so preserve this complicated case. For now, this
+# test will guarantee that the bitmaps are computed
+# correctly, even with the repeat calculations.
 
 test_expect_success 'setup repo with moderate-sized history' '
 	test_commit_bulk --id=file 10 &&
@@ -113,7 +114,7 @@ test_expect_success 'full repack creates bitmaps' '
 	ls .git/objects/pack/ | grep bitmap >output &&
 	test_line_count = 1 output &&
 	grep "\"key\":\"num_selected_commits\",\"value\":\"106\"" trace &&
-	grep "\"key\":\"num_maximal_commits\",\"value\":\"111\"" trace
+	grep "\"key\":\"num_maximal_commits\",\"value\":\"107\"" trace
 '
 
 test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
-- 
2.29.2.312.gabc4d358d8
Previous: Taylor BlauNext: Jonathan Tan
Message 93 of 173 in “pack-bitmap: bitmap generation improvements”
  1. 00/23 pack-bitmap: bitmap generation improvementsTaylor Blau, Nov 11, 2020
  2. 01/23 ewah/ewah_bitmap.c: grow buffer past 1Taylor Blau, Nov 11, 2020
  3. Junio C HamanoNov 22, 2020
  4. Taylor BlauNov 23, 2020
  5. Jeff KingNov 24, 2020
  6. Jeff KingNov 24, 2020
  7. Taylor BlauDec 1, 2020
  8. 02/23 pack-bitmap: fix header size checkTaylor Blau, Nov 11, 2020
  9. Martin ÅgrenNov 12, 2020
  10. 03/23 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Nov 11, 2020
  11. Martin ÅgrenNov 12, 2020
  12. Jeff KingNov 13, 2020
  13. Martin ÅgrenNov 13, 2020
  14. Taylor BlauNov 13, 2020
  15. Jeff KingNov 13, 2020
  16. Taylor BlauNov 13, 2020
  17. Jeff KingNov 13, 2020
  18. 04/23 t5310: drop size of truncated ewah bitmapTaylor Blau, Nov 11, 2020
  19. 05/23 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Nov 11, 2020
  20. 06/23 ewah: factor out bitmap growthTaylor Blau, Nov 11, 2020
  21. 07/23 ewah: make bitmap growth less aggressiveTaylor Blau, Nov 11, 2020
  22. Junio C HamanoNov 22, 2020
  23. Taylor BlauNov 23, 2020
  24. Jeff KingNov 24, 2020
  25. Junio C HamanoNov 24, 2020
  26. 08/23 ewah: implement bitmap_or()Taylor Blau, Nov 11, 2020
  27. Junio C HamanoNov 22, 2020
  28. Taylor BlauNov 23, 2020
  29. 09/23 ewah: add bitmap_dup() functionTaylor Blau, Nov 11, 2020
  30. 10/23 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Nov 11, 2020
  31. 11/23 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Nov 11, 2020
  32. 12/23 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Nov 11, 2020
  33. 13/23 bitmap: add bitmap_diff_nonzero()Taylor Blau, Nov 11, 2020
  34. 14/23 commit: implement commit_list_contains()Taylor Blau, Nov 11, 2020
  35. 15/23 t5310: add branch-based checksTaylor Blau, Nov 11, 2020
  36. Derrick StoleeNov 11, 2020
  37. Junio C HamanoNov 11, 2020
  38. Johannes SchindelinNov 15, 2020
  39. 16/23 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Nov 11, 2020
  40. 17/23 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Nov 11, 2020
  41. SZEDER GáborNov 13, 2020
  42. Jeff KingNov 13, 2020
  43. Jeff KingNov 14, 2020
  44. 18/23 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Nov 11, 2020
  45. 19/23 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Nov 11, 2020
  46. 20/23 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Nov 11, 2020
  47. 21/23 pack-bitmap-write: use existing bitmapsTaylor Blau, Nov 11, 2020
  48. 22/23 pack-bitmap-write: relax unique rewalk conditionTaylor Blau, Nov 11, 2020
  49. 23/23 pack-bitmap-write: better reuse bitmapsTaylor Blau, Nov 11, 2020
  50. 00/24 pack-bitmap: bitmap generation improvementsTaylor Blau, Nov 17, 2020
  51. 01/24 ewah/ewah_bitmap.c: grow buffer past 1Taylor Blau, Nov 17, 2020
  52. 02/24 pack-bitmap: fix header size checkTaylor Blau, Nov 17, 2020
  53. 03/24 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Nov 17, 2020
  54. 04/24 t5310: drop size of truncated ewah bitmapTaylor Blau, Nov 17, 2020
  55. 05/24 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Nov 17, 2020
  56. 06/24 ewah: factor out bitmap growthTaylor Blau, Nov 17, 2020
  57. 07/24 ewah: make bitmap growth less aggressiveTaylor Blau, Nov 17, 2020
  58. 08/24 ewah: implement bitmap_or()Taylor Blau, Nov 17, 2020
  59. 09/24 ewah: add bitmap_dup() functionTaylor Blau, Nov 17, 2020
  60. 10/24 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Nov 17, 2020
  61. Jonathan TanNov 25, 2020
  62. Taylor BlauNov 28, 2020
  63. 11/24 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Nov 17, 2020
  64. Jonathan TanNov 25, 2020
  65. 12/24 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Nov 17, 2020
  66. Junio C HamanoNov 22, 2020
  67. Derrick StoleeNov 23, 2020
  68. Jonathan TanNov 25, 2020
  69. Taylor BlauNov 28, 2020
  70. Jonathan TanNov 30, 2020
  71. 13/24 bitmap: add bitmap_diff_nonzero()Taylor Blau, Nov 17, 2020
  72. Junio C HamanoNov 22, 2020
  73. Taylor BlauNov 23, 2020
  74. 14/24 commit: implement commit_list_contains()Taylor Blau, Nov 17, 2020
  75. 15/24 t5310: add branch-based checksTaylor Blau, Nov 17, 2020
  76. Jonathan TanNov 25, 2020
  77. Taylor BlauNov 28, 2020
  78. 16/24 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Nov 17, 2020
  79. 17/24 pack-bitmap.c: check reads more aggressively when loadingTaylor Blau, Nov 17, 2020
  80. 18/24 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Nov 17, 2020
  81. Jonathan TanNov 24, 2020
  82. Jonathan TanNov 25, 2020
  83. Derrick StoleeNov 30, 2020
  84. 19/24 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Nov 17, 2020
  85. Jonathan TanDec 2, 2020
  86. 20/24 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Nov 17, 2020
  87. Jonathan TanDec 2, 2020
  88. 21/24 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Nov 17, 2020
  89. Jonathan TanDec 2, 2020
  90. 22/24 pack-bitmap-write: use existing bitmapsTaylor Blau, Nov 17, 2020
  91. Jonathan TanDec 2, 2020
  92. Taylor BlauDec 2, 2020
  93. 23/24 pack-bitmap-write: relax unique rewalk conditionTaylor Blau, Nov 17, 2020
  94. Jonathan TanDec 2, 2020
  95. Taylor BlauDec 2, 2020
  96. Jonathan TanDec 7, 2020
  97. Derrick StoleeDec 7, 2020
  98. Derrick StoleeDec 7, 2020
  99. Jeff KingDec 7, 2020
  100. 24/24 pack-bitmap-write: better reuse bitmapsTaylor Blau, Nov 17, 2020
  101. Jonathan TanDec 2, 2020
  102. Taylor BlauDec 2, 2020
  103. Derrick StoleeDec 2, 2020
  104. Taylor BlauDec 2, 2020
  105. Jonathan TanDec 7, 2020
  106. Jonathan TanDec 7, 2020
  107. Derrick StoleeDec 7, 2020
  108. SZEDER GáborNov 18, 2020
  109. Taylor BlauNov 18, 2020
  110. Taylor BlauNov 22, 2020
  111. Taylor BlauNov 22, 2020
  112. Martin ÅgrenNov 20, 2020
  113. Junio C HamanoNov 21, 2020
  114. Martin ÅgrenNov 21, 2020
  115. Taylor BlauNov 22, 2020
  116. Jeff KingNov 24, 2020
  117. Taylor BlauDec 1, 2020
  118. Jonathan TanDec 1, 2020
  119. Taylor BlauDec 1, 2020
  120. Jonathan TanDec 2, 2020
  121. 00/24 pack-bitmap: bitmap generation improvementsTaylor Blau, Dec 8, 2020
  122. 01/24 ewah/ewah_bitmap.c: avoid open-coding ALLOC_GROW()Taylor Blau, Dec 8, 2020
  123. 02/24 pack-bitmap: fix header size checkTaylor Blau, Dec 8, 2020
  124. 03/24 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Dec 8, 2020
  125. 05/24 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Dec 8, 2020
  126. 04/24 t5310: drop size of truncated ewah bitmapTaylor Blau, Dec 8, 2020
  127. 08/24 ewah: implement bitmap_or()Taylor Blau, Dec 8, 2020
  128. 07/24 ewah: make bitmap growth less aggressiveTaylor Blau, Dec 8, 2020
  129. 09/24 ewah: add bitmap_dup() functionTaylor Blau, Dec 8, 2020
  130. 11/24 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Dec 8, 2020
  131. 06/24 ewah: factor out bitmap growthTaylor Blau, Dec 8, 2020
  132. 12/24 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Dec 8, 2020
  133. 10/24 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Dec 8, 2020
  134. 13/24 bitmap: implement bitmap_is_subset()Taylor Blau, Dec 8, 2020
  135. 14/24 commit: implement commit_list_contains()Taylor Blau, Dec 8, 2020
  136. 15/24 t5310: add branch-based checksTaylor Blau, Dec 8, 2020
  137. 17/24 pack-bitmap.c: check reads more aggressively when loadingTaylor Blau, Dec 8, 2020
  138. 16/24 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Dec 8, 2020
  139. 22/24 pack-bitmap-write: use existing bitmapsTaylor Blau, Dec 8, 2020
  140. 18/24 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Dec 8, 2020
  141. 20/24 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Dec 8, 2020
  142. 19/24 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Dec 8, 2020
  143. 21/24 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Dec 8, 2020
  144. 23/24 pack-bitmap-write: relax unique rewalk conditionTaylor Blau, Dec 8, 2020
  145. 24/24 pack-bitmap-write: better reuse bitmapsTaylor Blau, Dec 8, 2020
  146. Junio C HamanoDec 8, 2020
  147. Taylor BlauDec 8, 2020
  148. Junio C HamanoDec 8, 2020
  149. 00/24 pack-bitmap: bitmap generation improvementsTaylor Blau, Dec 8, 2020
  150. 02/24 pack-bitmap: fix header size checkTaylor Blau, Dec 8, 2020
  151. 01/24 ewah/ewah_bitmap.c: avoid open-coding ALLOC_GROW()Taylor Blau, Dec 8, 2020
  152. 04/24 t5310: drop size of truncated ewah bitmapTaylor Blau, Dec 8, 2020
  153. 03/24 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Dec 8, 2020
  154. 05/24 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Dec 8, 2020
  155. 06/24 ewah: factor out bitmap growthTaylor Blau, Dec 8, 2020
  156. 07/24 ewah: make bitmap growth less aggressiveTaylor Blau, Dec 8, 2020
  157. 12/24 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Dec 8, 2020
  158. 10/24 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Dec 8, 2020
  159. 09/24 ewah: add bitmap_dup() functionTaylor Blau, Dec 8, 2020
  160. 08/24 ewah: implement bitmap_or()Taylor Blau, Dec 8, 2020
  161. 11/24 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Dec 8, 2020
  162. 13/24 bitmap: implement bitmap_is_subset()Taylor Blau, Dec 8, 2020
  163. 15/24 t5310: add branch-based checksTaylor Blau, Dec 8, 2020
  164. 16/24 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Dec 8, 2020
  165. 17/24 pack-bitmap.c: check reads more aggressively when loadingTaylor Blau, Dec 8, 2020
  166. 19/24 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Dec 8, 2020
  167. 20/24 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Dec 8, 2020
  168. 22/24 pack-bitmap-write: use existing bitmapsTaylor Blau, Dec 8, 2020
  169. 14/24 commit: implement commit_list_contains()Taylor Blau, Dec 8, 2020
  170. 18/24 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Dec 8, 2020
  171. 23/24 pack-bitmap-write: relax unique revwalk conditionTaylor Blau, Dec 8, 2020
  172. 24/24 pack-bitmap-write: better reuse bitmapsTaylor Blau, Dec 8, 2020
  173. 21/24 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Dec 8, 2020

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.