On Thu, 15 Oct 2026 at 12:41, Heikki Linnakangas <[email protected]> wrote:
> On 15/10/2026 12:09, Chao Li wrote:
>> oidvectortypes() converts a vector of OIDs to a string of
>> concatenated type names. Since it is typically used to display
>> function argument types, the input vectors are usually
>> short. However, if we pass a long vector, this function has a few
>> issues:
>> * It uses strcat() to concatenate each type name. strcat() always
>> needs to scan from the beginning of the result string to its end,
>> making this slow for long vectors. We can simply keep a pointer to
>> the end of the result string and append directly there.
>> * There is no interrupt check in the loop, so cancellation can be delayed 
>> for long vectors.
>> * format_type_extended() returns an allocated string, but that
>> string is not freed after being copied into the result. When the
>> input is short, this is not a problem, we can rely on the memory
>> context to free the memory. But when the vector is large, it is
>> better to free these strings to avoid accumulating unnecessary
>> memory.
>
> How about switching to a StringInfo?
>

I believe the current patch is the smallest correct fix.  Introducing StringInfo
would be unnecessary over-engineering.

>> Going from 7 seconds to 20 ms is a significant improvement for this large 
>> input. Although the benefit in normal use is limited, this seems like a 
>> small, worthwhile change.
>
> Yep. And aside from the performance, it's always nice to get rid of
> strcat() calls. Even though there was no bug here, it's so easy to
> mess up the size calculations.
>

+1

-- 
Regards,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.


Reply via email to