Message ID | 20230203234430.M553381@dcvr (mailing list archive) |
---|---|
State | Accepted |
Commit | 647982bb7171b2409f2a90da245b8a31913f930f |
Headers | show |
Series | [v3] delta-islands: free island_marks and bitmaps | expand |
On Fri, Feb 03, 2023 at 11:44:30PM +0000, Eric Wong wrote: > > /* If we aren't using islands, assume everything goes together. */ > > - if (!island_marks) > > + if (!using_island_marks) > > return 1; > > I much prefer to rely on invalid pointers than extra flags since > having multiple sources of truth confuses me[1]. That's kind of my point, though. It's not multiple sources of truth, but rather there are two bits "did we ask to use islands" and "is island_marks still valid". You are shoving both bits into the same variable by using a special sentinel pointer. > > And of course that would also be a tiny step in the right direction if > > the delta islands API learned to use a struct (this would be the same > > spot where we'd say "we're done with islands; free the struct"). > > I do wonder about performance on register-starved systems, > though, especially if stuff like island_delta_cmp gets called > frequently. I already have enough performance problems atm :< Calling in_same_island() is pretty heavy-weight (it's multiple hash lookups, and then an arbitrary-length bit-string comparison). I'd be shocked if replacing a global with a struct pointer is even measurable. > [1] to go farther, I might even eliminate `int use_delta_islands' as > a global from builtin/pack-objects.c and just have that become a > `struct delta_islands_foo *' or something. But I have more > pressing performance problems to figure out :< Right, that's along the same lines I was thinking. But I don't blame you for not tackling it. The upside is fairly minimal. > + /* detect use-after-free with a an address which is never valid: */ > + island_marks = (void *)-1; I still hate how magical this line is, but I don't that it's worth arguing about more. -Peff
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index cabace4abb..3395f63aba 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -929,8 +929,10 @@ static struct object_entry **compute_write_order(void) */ for_each_tag_ref(mark_tagged, NULL); - if (use_delta_islands) + if (use_delta_islands) { max_layers = compute_pack_layers(&to_pack); + free_island_marks(); + } ALLOC_ARRAY(wo, to_pack.nr_objects); wo_end = 0; diff --git a/delta-islands.c b/delta-islands.c index 90c0d6958f..8b234cb85b 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -513,6 +513,20 @@ void propagate_island_marks(struct commit *commit) } } +void free_island_marks(void) +{ + struct island_bitmap *bitmap; + + kh_foreach_value(island_marks, bitmap, { + if (!--bitmap->refcount) + free(bitmap); + }); + kh_destroy_oid_map(island_marks); + + /* detect use-after-free with a an address which is never valid: */ + island_marks = (void *)-1; +} + int compute_pack_layers(struct packing_data *to_pack) { uint32_t i; diff --git a/delta-islands.h b/delta-islands.h index eb0f952629..8d1591ae28 100644 --- a/delta-islands.h +++ b/delta-islands.h @@ -14,5 +14,6 @@ void resolve_tree_islands(struct repository *r, void load_delta_islands(struct repository *r, int progress); void propagate_island_marks(struct commit *commit); int compute_pack_layers(struct packing_data *to_pack); +void free_island_marks(void); #endif /* DELTA_ISLANDS_H */