[PATCH] Precompute string lengths in PerformRadiusTransaction

Started by zengman11 months ago6 messageshackers
Jump to latest
#1zengman
zengman@halodbtech.com

Hi, hackers

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.

--
Regards,
Man Zeng
www.openhalo.org

Attachments:

0001-Precompute-string-lengths-in-PerformRadiusTransactio.patchapplication/octet-stream; charset=gb18030; name=0001-Precompute-string-lengths-in-PerformRadiusTransactio.patchDownload+11-10
#2Aleksander Alekseev
aleksander@tigerdata.com
In reply to: zengman (#1)
Re: [PATCH] Precompute string lengths in PerformRadiusTransaction

Hi,

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`.

--
Best regards,
Aleksander Alekseev

#3zengman
zengman@halodbtech.com
In reply to: Aleksander Alekseev (#2)
Re: [PATCH] Precompute string lengths in PerformRadiusTransaction

Good find. We may also consider making both passwd_len and secret_len `const`.

Thanks ! — Added const for passwd_len and secret_len.

--
Regards,
Man Zeng
www.openhalo.org

Attachments:

t53024_3
0002-Precompute-string-lengths-in-PerformRadiusTransactio.patchapplication/octet-stream; charset=gb18030; name=0002-Precompute-string-lengths-in-PerformRadiusTransactio.patchDownload+11-10
#4Andreas Karlsson
andreas.karlsson@percona.com
In reply to: Aleksander Alekseev (#2)
Re: [PATCH] Precompute string lengths in PerformRadiusTransaction

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

#5John Naylor
johncnaylorls@gmail.com
In reply to: zengman (#1)
Re: [PATCH] Precompute string lengths in PerformRadiusTransaction

On Mon, Jan 5, 2026 at 9:36 PM zengman <zengman@halodbtech.com> 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.

Shortly after you posted this, it was decided that we're going to
remove this method entirely:

https://wiki.postgresql.org/wiki/RADIUS

--
John Naylor
Amazon Web Services

#6zengman
zengman@halodbtech.com
In reply to: John Naylor (#5)
Re: [PATCH] Precompute string lengths in PerformRadiusTransaction

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.

Shortly after you posted this, it was decided that we're going to
remove this method entirely:

https://wiki.postgresql.org/wiki/RADIUS

Hi,

Okay, thank you very much for reminding me. I'll retract this patch.

--
regards,
Man Zeng