commit-reach: add trace2 instrumentation to paint_down_to_common()
Add a step counter and trace2_data_intmax() call so that the number of commits visited during the paint walk is observable via GIT_TRACE2_EVENT. This provides a way to measure the impact of future optimizations without relying on wall-clock benchmarks alone. Signed-off-by: Kristofer Karlsson <krka@spotify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristofer Karlsson committed
Jul 11, 2026 at 13:27 UTC
47183400bf054d29c33266e0dd18d4d8b31a5a17
2 files changed
+36
-13
commit-reach.c
+5
@@ -11,6 +11,7 @@
11
#include "tag.h"
12
#include "commit-reach.h"
13
#include "ewah/ewok.h"
14
+#include "trace2.h"
15
16
/* Remember to update object flag allocation in object.h */
17
#define PARENT1 (1u<<16)
@@ -113,6 +114,7 @@ static int paint_down_to_common(struct repository *r,
114
};
115
int i;
116
int gen_ordered = 1;
117
+ int steps = 0;
118
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
119
struct commit_list **tail = result;
120
@@ -138,6 +140,7 @@ static int paint_down_to_common(struct repository *r,
140
struct commit_list *parents;
141
int flags;
142
timestamp_t generation = commit_graph_generation(commit);
143
+ steps++;
144
145
if (min_generation && generation > last_gen)
146
BUG("bad generation skip %"PRItime" > %"PRItime" at %s",
@@ -194,6 +197,8 @@ static int paint_down_to_common(struct repository *r,
197
}
198
199
clear_nonstale_queue(&queue);
200
+ trace2_data_intmax("paint_down_to_common", r,
201
+ "steps", steps);
202
commit_list_sort_by_date(result);
203
return 0;
204
}
t/t6600-test-reach.sh
+31
-13
@@ -153,24 +153,34 @@ test_expect_success 'setup' '
153
'
154
155
run_all_modes () {
156
- test_when_finished rm -rf .git/objects/info/commit-graph &&
157
- "$@" <input >actual &&
158
- test_cmp expect actual &&
159
- cp commit-graph-full .git/objects/info/commit-graph &&
160
- "$@" <input >actual &&
161
- test_cmp expect actual &&
162
- cp commit-graph-half .git/objects/info/commit-graph &&
163
- "$@" <input >actual &&
164
- test_cmp expect actual &&
165
- cp commit-graph-no-gdat .git/objects/info/commit-graph &&
166
- "$@" <input >actual &&
167
- test_cmp expect actual
156
+ graph=.git/objects/info/commit-graph &&
157
+ test_when_finished rm -rf "$graph" "${graph}s" &&
158
+ rm -f trace-mode-*.txt &&
159
+
160
+ for mode in none full half no-gdat
161
+ do
162
+ rm -rf "$graph" "${graph}s" &&
163
+ cp "commit-graph-${mode}" "$graph" 2>/dev/null ||
164
+ true &&
165
+ GIT_TRACE2_EVENT="$(pwd)/trace-mode-${mode}.txt" \
166
+ "$@" <input >actual &&
167
+ test_cmp expect actual || return 1
168
+ done
169
}
170
171
test_all_modes () {
172
run_all_modes test-tool reach "$@"
173
}
174
175
+test_paint_down_steps () {
176
+ for mode in none full half no-gdat
177
+ do
178
+ test_trace2_data_singular paint_down_to_common steps "$1" \
179
+ "mode=$mode" <"trace-mode-${mode}.txt" || return 1
180
+ shift
181
+ done
182
+}
183
+
184
test_expect_success 'ref_newer:miss' '
185
cat >input <<-\EOF &&
186
A:commit-5-7
@@ -244,7 +254,8 @@ test_expect_success 'in_merge_bases_many:self' '
254
X:commit-6-8
255
EOF
256
echo "in_merge_bases_many(A,X):1" >expect &&
247
- test_all_modes in_merge_bases_many
257
+ test_all_modes in_merge_bases_many &&
258
+ test_paint_down_steps 45 2 25 3
259
'
260
261
test_expect_success 'is_descendant_of:hit' '
@@ -329,6 +340,13 @@ test_expect_success 'get_merge_bases_many:infinity-both-sides' '
340
test_all_modes get_merge_bases_many
341
'
342
343
+test_expect_success 'merge-base --all commit-walk steps' '
344
+ >input &&
345
+ git rev-parse commit-9-1 >expect &&
346
+ run_all_modes git merge-base --all commit-9-9 commit-9-1 &&
347
+ test_paint_down_steps 81 80 81 81
348
+'
349
+
350
test_expect_success 'reduce_heads' '
351
cat >input <<-\EOF &&
352
X:commit-1-10