| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Avoid repeated scans of the output buffer in oidvectortypes() |
| Date: | 2026-10-15 09:41:04 |
| Message-ID: | 36b0c141-24a6-45df-b3fe-46af701412d4@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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?
> 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.
- Heikki
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nisha Moond | 2026-10-15 09:52:11 | Re: Proposal: Conflict log history table for Logical Replication |
| Previous Message | Heikki Linnakangas | 2026-10-15 09:36:12 | Re: [PATCH] pg_test_fsync: close Windows alarm thread handles |