Re: [PATCH 20/20] pack-revindex.c: avoid direct revindex access in 'offset_to_pack_pos()'
- From
Jeff King <peff@peff.net>
- Date
- Jan 12, 2021, 09:37 UTC
- Message-ID
- <X/1txTIxV4pYt0Xo@coredump.intra.peff.net>
- In-Reply-To
- <eada1ffcfafc3fb57de80626e368672cb8b22318.1610129796.git.me@ttaylorr.com>
On Fri, Jan 08, 2021 at 01:18:06PM -0500, Taylor Blau wrote:
Show 13 quoted lines
> To prepare for on-disk reverse indexes, remove a spot in > 'offset_to_pack_pos()' that looks at the 'revindex' array in 'struct > packed_git'. > > Even though this use of the revindex pointer is within pack-revindex.c, > this clean up is still worth doing. Since the 'revindex' pointer will be > NULL when reading from an on-disk reverse index (instead the > 'revindex_data' pointer will be mmaped to the 'pack-*.rev' file), this > call-site would have to include a conditional to lookup the offset for > position 'mi' each iteration through the search. > > So instead of open-coding 'pack_pos_to_offset()', call it directly from > within 'offset_to_pack_pos()'.
This definitely makes sense in the long run. I could take or leave it as a final patch in _this_ series (as opposed to the first patch in a subsequent series adding the rev files).
> do {
> const unsigned mi = lo + (hi - lo) / 2;
> - if (revindex[mi].offset == ofs) {
> + off_t got = pack_pos_to_offset(p, mi);They're both constant-time, so performance should be the same big-O. The function has extra BUG() checks. I doubt those are measurable in practice, though.
-Peff