Re: [PATCH v2 12/12] remote: use strmap for apply_push_cas()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 5, 2026, 22:49 UTC
- Message-ID
- <xmqqik2aq4fx.fsf@gitster.g>
- In-Reply-To
- <20261014031347.50433-13-jon@jonsimons.org>
Jon Simons <jon@jonsimons.org> writes:
Show 9 quoted lines
> Optimize apply_push_cas() by replacing a linear traversal of all > advertised remote refs with strmap lookups. > > Before this change, applying N explicit --force-with-lease entries > to M remote advertised refs entails O(N * M) calls to refname_match() > in apply_one_cas(). > > After this change, we build a strmap of remote refs O(M), and use it > for O(N * rules) lookups of the lease entry refnames.
OK. We may be checking multiple target refs, and we may be checking with multiple cas rules, but the order of check does not matter, so we do not have to be linearly scanning the remote_refs list at all.
> The refnames are resolved by issuing one strmap lookup for each > candidate rules pattern generated with expand_ref_prefix(), as > with earlier strmap conversions.
That trick is clever and apparently very effective ...
Show 10 quoted lines
> p5516 timings show the speedup: > > Test HEAD~1 HEAD > -------------------------------------------------------------------- > 5516.16: empty:lease:1 0.13(0.07+0.10) 0.14(0.08+0.11) +7.7% > 5516.19: empty:lease:10 0.16(0.10+0.10) 0.14(0.08+0.11) -12.5% > 5516.22: empty:lease:100 0.45(0.39+0.10) 0.16(0.09+0.11) -64.4% > 5516.25: mirror:lease:1 0.16(0.09+0.11) 0.17(0.10+0.12) +6.3% > 5516.28: mirror:lease:10 0.19(0.12+0.10) 0.17(0.10+0.11) -10.5% > 5516.31: mirror:lease:100 0.49(0.42+0.12) 0.19(0.11+0.12) -61.2%
... which is very nice.
Thanks.