Re: Get rid of redundant StringInfo accumulation

From: Daniil Davydov <3danissimo(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Get rid of redundant StringInfo accumulation
Date: 2026-03-30 14:24:01
Message-ID: CAJDiXgjPGu_cW9nsvciqdgAkqY5o5ugaxDvo3S-rOcqBPcHCPw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Mar 30, 2026 at 7:52 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
>
> I don't see when the overhead of creating an populating the string info ever
> matters in these cases. This is optimizing something that never can matter for
> real world performance. Even if it were worth optimizing them, I doubt that
> the log level check is useful here, because most if not all of these are
> logged with a level that's logged in nearly all installations.
>

Thank you for the review!

I have a few arguments to defend this patch :
1)
It is normal practice in the code base to check log level before allocating
memory for StringInfo or some other structure. For example, I found the log
level check even before a very lightweight piece of code (see xlogutils.c)
and even if we are going to emit log with DEBUG3 level (see postmaster.c).
2)
Originally, I created this patch in order to avoid spending time during
acquiring LWLock before entering the GetLockHoldersAndWaiters function. The
log_lock_waits parameter is "true" by default, so even if log level is high,
we will *waste* time on the lock acquiring. I.e. this patch is not only about
getting rid of redundant memory allocation - it is also about reducing waiting
time on the locks. I think that it may be noticeable in conditions of a huge
number of parallel processes.
3)
I don't think that all other places (except lock.c and proc.c) where I have
added log level check are really matter for real world performance. This is
more about consistent approach : if we check log level in lock.c, then we
should check it everywhere (if it makes sense). Again, it is normal practice
for the postgres' code.

Am I missing something?

BTW, during writing it I noticed that I forgot to add log level check for
pretty important code path (proc.c). Please, see it in the v3 patch.

--
Best regards,
Daniil Davydov

Attachment Content-Type Size
v3-0001-Get-rid-of-redundant-calculations.patch text/x-patch 4.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anton A. Melnikov 2026-03-30 14:25:29 [BUG] Excessive memory usage with update on STORED generated columns.
Previous Message Heikki Linnakangas 2026-03-30 14:18:03 Re: Clean up NamedLWLockTranche stuff