Skip to content

Commit f13ca7c

Browse files
rscharfegitster
authored andcommitted
name-rev: put struct rev_name into commit slab
The commit slab commit_rev_name contains a pointer to a struct rev_name, and the actual struct is allocated separatly. Avoid that allocation and pointer indirection by storing the full struct in the commit slab. Use the tip_name member pointer to determine if the returned struct is initialized. Performance in the Linux repository measured with hyperfine before: Benchmark #1: ./git -C ../linux/ name-rev --all Time (mean ± σ): 953.5 ms ± 6.3 ms [User: 901.2 ms, System: 52.1 ms] Range (min … max): 945.2 ms … 968.5 ms 10 runs ... and with this patch: Benchmark #1: ./git -C ../linux/ name-rev --all Time (mean ± σ): 851.0 ms ± 3.1 ms [User: 807.4 ms, System: 43.6 ms] Range (min … max): 846.7 ms … 857.0 ms 10 runs Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d689d6d commit f13ca7c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

builtin/name-rev.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ struct rev_name {
2424
int from_tag;
2525
};
2626

27-
define_commit_slab(commit_rev_name, struct rev_name *);
27+
define_commit_slab(commit_rev_name, struct rev_name);
2828

2929
static timestamp_t cutoff = TIME_MAX;
3030
static struct commit_rev_name rev_names;
3131

3232
/* How many generations are maximally preferred over _one_ merge traversal? */
3333
#define MERGE_TRAVERSAL_WEIGHT 65535
3434

35+
static int is_valid_rev_name(const struct rev_name *name)
36+
{
37+
return name && name->tip_name;
38+
}
39+
3540
static struct rev_name *get_commit_rev_name(const struct commit *commit)
3641
{
37-
struct rev_name **slot = commit_rev_name_peek(&rev_names, commit);
42+
struct rev_name *name = commit_rev_name_peek(&rev_names, commit);
3843

39-
return slot ? *slot : NULL;
44+
return is_valid_rev_name(name) ? name : NULL;
4045
}
4146

4247
static int is_better_name(struct rev_name *name,
@@ -81,15 +86,12 @@ static struct rev_name *create_or_update_name(struct commit *commit,
8186
int generation, int distance,
8287
int from_tag)
8388
{
84-
struct rev_name **slot = commit_rev_name_at(&rev_names, commit);
85-
struct rev_name *name = *slot;
89+
struct rev_name *name = commit_rev_name_at(&rev_names, commit);
8690

87-
if (name && !is_better_name(name, taggerdate, distance, from_tag))
91+
if (is_valid_rev_name(name) &&
92+
!is_better_name(name, taggerdate, distance, from_tag))
8893
return NULL;
8994

90-
if (!name)
91-
name = *slot = xmalloc(sizeof(*name));
92-
9395
name->tip_name = tip_name;
9496
name->taggerdate = taggerdate;
9597
name->generation = generation;

0 commit comments

Comments
 (0)