From: Patrick Steinhardt <ps@pks.im>
To: yusuke8h@gmail.com
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v2] http-backend: drop strbuf pre-sizing from get_info_packs()
Date: Mon, 16 Nov 2026 07:29:44 +0100 [thread overview]
Message-ID: <avqi2Jpd-QT5iNU9@pks.im> (raw)
In-Reply-To: <20261115-http-backend-drop-strbuf-presizing-v2-1-b7ffe1be4482@gmail.com>
On Sun, Nov 15, 2026 at 09:58:47AM +0000, Yusuke Hayashi via B4 Relay wrote:
> From: Yusuke Hayashi <yusuke8h@gmail.com>
>
> `get_info_packs()` iterates over all packs in the repository to count
> local packs, calls `strbuf_grow(&buf, cnt * 53 + 2)`, and then iterates
> over the packs a second time to format each entry with `strbuf_addf()`.
> This pre-sizing dates back to 2f4038ab33 (Git-aware CGI to provide dumb
> HTTP transport, 2009-10-30): `53` assumes the length of a SHA-1
> "P pack-<hex>.pack\n" line (under-counting the 77-byte lines in SHA-256
> repositories), and `cnt * 53 + 2` uses unchecked arithmetic.
>
> Rather than fixing the size calculation with `the_hash_algo->hexsz` and
> `st_mult()` / `st_add()`, drop the pre-sizing altogether.
> `get_info_packs()` is a one-shot CGI handler for dumb HTTP
> `/objects/info/packs` requests that formats a single response and exits.
> A typical repository only has a few dozen packs (a few kilobytes of
> output), and even with thousands of packs `strbuf`'s geometric growth
> only performs a couple dozen reallocations. That cost is negligible next
> to CGI startup, scanning `objects/pack` to populate the pack list, and
> writing the HTTP response, whereas computing `cnt` up front requires an
> extra pass over the pack list.
Yeah, that's a much more convincing message. The other angle that this
is missing a bit is that giving a size hint ensures that we allocate
exactly as many bytes as we need. But that shouldn't matter in the
general case, and if you have to allocate gigabytes of memory to store
the list of packfiles... well, then you really have bigger problems to
worry about.
So I think this version is good enough, thanks!
Patrick
next prev parent reply other threads:[~2026-11-16 6:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 2:17 [PATCH] http-backend: drop strbuf pre-sizing from get_info_packs() Yusuke Hayashi
2026-11-13 2:17 ` Yusuke Hayashi via B4 Relay
2026-11-13 7:03 ` Patrick Steinhardt
2026-11-15 9:58 ` Yusuke Hayashi
2026-11-15 9:58 ` [PATCH v2] " Yusuke Hayashi via B4 Relay
2026-11-15 9:58 ` Yusuke Hayashi
2026-11-16 6:29 ` Patrick Steinhardt [this message]
2026-11-16 15:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avqi2Jpd-QT5iNU9@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=yusuke8h@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.