diff mbox series

[v5,16/16] ls-refs.c: avoid enumerating hidden refs where possible

Message ID dff068c469f9c59c94775209e34edfb678b627d9.1689023520.git.me@ttaylorr.com (mailing list archive)
State Accepted
Commit 98456eff08069696708b24ab4f1152f06a3b47f9
Headers show
Series refs: implement jump lists for packed backend | expand

Commit Message

Taylor Blau July 10, 2023, 9:12 p.m. UTC
In a similar fashion as in previous commits, teach `ls-refs` to avoid
enumerating hidden references where possible.

As before, this is linux.git with one hidden reference per commit.

    $ hyperfine -L v ,.compile 'git{v} -c protocol.version=2 ls-remote .'
    Benchmark 1: git -c protocol.version=2 ls-remote .
      Time (mean ± σ):      89.8 ms ±   0.6 ms    [User: 84.3 ms, System: 5.7 ms]
      Range (min … max):    88.8 ms …  91.3 ms    32 runs

    Benchmark 2: git.compile -c protocol.version=2 ls-remote .
      Time (mean ± σ):       6.5 ms ±   0.1 ms    [User: 2.4 ms, System: 4.3 ms]
      Range (min … max):     6.2 ms …   8.3 ms    397 runs

    Summary
      'git.compile -c protocol.version=2 ls-remote .' ran
       13.85 ± 0.33 times faster than 'git -c protocol.version=2 ls-remote .'

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 ls-refs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ls-refs.c b/ls-refs.c
index 9291ddfdf8c..0e49b932c30 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -194,7 +194,8 @@  int ls_refs(struct repository *r, struct packet_reader *request)
 		strvec_push(&data.prefixes, "");
 	refs_for_each_fullref_in_prefixes(get_main_ref_store(r),
 					  get_git_namespace(), data.prefixes.v,
-					  NULL, send_ref, &data);
+					  hidden_refs_to_excludes(&data.hidden_refs),
+					  send_ref, &data);
 	packet_fflush(stdout);
 	strvec_clear(&data.prefixes);
 	strbuf_release(&data.buf);