Re: [PATCH] Precompute string lengths in PerformRadiusTransaction

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: zengman <zengman(at)halodbtech(dot)com>
Subject: Re: [PATCH] Precompute string lengths in PerformRadiusTransaction
Date: 2026-01-14 05:09:26
Message-ID: 9d030182-92e8-401b-b82b-3f16917d0e15@proxel.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 1/5/26 3:51 PM, Aleksander Alekseev wrote:
>> I noticed that the `PerformRadiusTransaction` function is invoked in a loop,
>> and the function itself contains internal loops that repeatedly call strlen() on the 'passwd' and 'secret' strings.
>> While the optimization gain may be minimal, I still think it’s worth making the change —
>> we can precompute the lengths of these two strings at the start of the function to eliminate redundant strlen() calls.
>
> Good find. We may also consider making both passwd_len and secret_len `const`.

I don't think this is a thing we generally do in our code. We have local
variables all over the place which do not use const.

The original patch looks good to me. While it is not a performance
critical code path calling strlen() in a loop is not very nice.

Andreas

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-01-14 05:15:48 Re: [PATCH] Change "the empty string" to "an empty string" on DOCs
Previous Message Andreas Karlsson 2026-01-14 04:42:36 Re: [PATCH] Change "the empty string" to "an empty string" on DOCs