Subject: Re: [PATCH 2/5] reftable/stack: add function to check if optimization is required

From: Junio C Hamano <[email-masked]>
Date: Fri, 31 Oct 2025 11:17:23 -0700

Justin Tobler <[email-masked]> writes:

>> +	err = stack_segments_for_compaction(st, &seg);
>> +	if (err)
>> +		return err;
>> +
>> +	*required = segment_size(&seg) > 0;
>
> As mentioned on the previous patch, I wonder if we could just return the
> number of tables in the compaction segment as part of
> `stack_segments_for_compaction()`. A negative value could indicate an
> error. All other values would reflect the number of tables to be
> compacted.
>
> This way callers interested in whether compaction should be performed
> could just do: stack_segments_for_compaction > 0. We could maybe avoid
> having a separate function like we do here and just expose
> `stack_segments_for_compaction()`.

Is the cost of compacting a single table expected to be roughly the
same across tables?  The number of tables to be compacted would not
be a useful information to help making a better decision otherwise,
so I am guessing that it is the underlying assumption the above
suggestion comes from.