]> Kevux Git Server - rit/commit
xdiff: optimize xdl_hash_record_verbatim
authorAlexander Monakov <amonakov@ispras.ru>
Mon, 28 Jul 2025 19:05:20 +0000 (22:05 +0300)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Aug 2025 15:44:49 +0000 (08:44 -0700)
commita4bbe8af0b48f9c80ccc2c4619309c4a81c1460a
treef7b10ef13dcdb4df810abe2946ca6376a6a1158b
parent41d97837ab1e5a35fdcfd7f6af9b5d56af62e92a
xdiff: optimize xdl_hash_record_verbatim

xdl_hash_record_verbatim uses modified djb2 hash with XOR instead of ADD
for combining. The ADD-based variant is used as the basis of the modern
("GNU") symbol lookup scheme in ELF. Glibc dynamic loader received an
optimized version of this hash function thanks to Noah Goldstein [1].

Switch xdl_hash_record_verbatim to additive hashing and implement
an optimized loop following the scheme suggested by Noah.

Timing 'git log --oneline --shortstat v2.0.0..v2.5.0' under perf, I got

version | cycles, bn | instructions, bn
---------------------------------------
A         6.38         11.3
B         6.21         10.89
C         5.80          9.95
D         5.83          8.74
---------------------------------------

A: baseline (git master at e4ef0485fd78)
B: plus 'xdiff: refactor xdl_hash_record()'
C: and plus this patch
D: with 'xdiff: use xxhash' by Phillip Wood

The resulting speedup for xdl_hash_record_verbatim itself is about 1.5x.

[1] https://inbox.sourceware.org/libc-alpha/20220519221803.57957-6-goldstein.w.n@gmail.com/

Signed-off-by: Alexander Monakov <amonakov@ispras.ru>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
xdiff/xutils.c