Re: Optimize scram_SaltedPassword performance

2025-02-03 Thread Michael Paquier
On Mon, Feb 03, 2025 at 12:17:27PM +0100, Daniel Gustafsson wrote: > The numbers are quite outdated but the gist of it holds. If we speed it up > serverside we need to counter that with a higher iteration count, and for a > rogue client it's unlikely to matter since it wont use our code anyways. >

Re: Optimize scram_SaltedPassword performance

2025-02-03 Thread Yura Sokolov
03.02.2025 14:17, Daniel Gustafsson пишет: >> On 3 Feb 2025, at 08:45, Yura Sokolov wrote: >> >> 03.02.2025 10:11, Zixuan Fu пишет: >>> Hi Hackers, >>> >>> While profiling a program with `perf`, I noticed that `scram_SaltedPassword` >>> consumed more CPU time than expected. After some investigat

Re: Optimize scram_SaltedPassword performance

2025-02-03 Thread Daniel Gustafsson
> On 3 Feb 2025, at 08:45, Yura Sokolov wrote: > > 03.02.2025 10:11, Zixuan Fu пишет: >> Hi Hackers, >> >> While profiling a program with `perf`, I noticed that `scram_SaltedPassword` >> consumed more CPU time than expected. After some investigation, I found >> that the function performs many

Re: Optimize scram_SaltedPassword performance

2025-02-03 Thread Fu Zixuan
I initially intended to restrict the modification to the scram_SaltedPassword(), but I'm unsure how to determine whether the current implementation is OpenSSL. Alternatively, could we modify pg_hmac_init() to allow `key=NULL` in the native HMAC implementation, achieving semantics similar to OpenSS

Re: Optimize scram_SaltedPassword performance

2025-02-03 Thread Michael Paquier
On Mon, Feb 03, 2025 at 03:11:48PM +0800, Zixuan Fu wrote: > With this change, the performance improves by approximately **4x** (reducing > execution time from 4ms to 1ms). The built-in PostgreSQL HMAC implementation > does not support context reuse, and modifying it would require substantial > cha

Re: Optimize scram_SaltedPassword performance

2025-02-02 Thread Yura Sokolov
03.02.2025 10:11, Zixuan Fu пишет: > Hi Hackers, > > While profiling a program with `perf`, I noticed that `scram_SaltedPassword` > consumed more CPU time than expected. After some investigation, I found > that the function performs many HMAC iterations (4096 rounds for > SCRAM-SHA-256), and eac

Optimize scram_SaltedPassword performance

2025-02-02 Thread Zixuan Fu
Hi Hackers, While profiling a program with `perf`, I noticed that `scram_SaltedPassword` consumed more CPU time than expected. After some investigation, I found that the function performs many HMAC iterations (4096 rounds for SCRAM-SHA-256), and each iteration reinitializes the HMAC context, cau