Improve performance of pg_strtointNN functions
От | David Rowley |
---|---|
Тема | Improve performance of pg_strtointNN functions |
Дата | |
Msg-id | CAApHDvrdYByjfj-=WbmVNFgmVZg88-dE7heukw8p55aJ+W=qxQ@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Improve performance of pg_strtointNN functions
|
Список | pgsql-hackers |
Over on [1], Dean and I were discussing why both gcc and clang don't seem to want to optimize the multiplication that we're doing in pg_strtoint16, pg_strtoint32 and pg_strtoint64 into something more efficient. It seems that this is down to the overflow checks. Removing seems to allow the compiler to better optimize the compiled code. See the use of LEA instead of IMUL in [2]. Instead of using the pg_mul_sNN_overflow functions, we can just accumulate the number in an unsigned version of the type and do an overflow check by checking if the accumulated value has gone beyond a 10th of the maximum *signed* value for the type. We then just need to do some final overflow checks after the accumulation is done. What those depend on if it's a negative or positive number. I ran a few microbenchmarks with the attached str2int.c file and I see about a 10-20% performance increase: $ ./str2int -100000000 100000000 n = -100000000, e = 100000000 pg_strtoint32 in 3.207926 seconds pg_strtoint32_v2 in 2.763062 seconds (16.100399% faster) v2 is the updated version of the function On Windows, the gains are generally a bit more. I think this must be due to the lack of overflow intrinsic functions. >str2int.exe -100000000 100000000 n = -100000000, e = 100000000 pg_strtoint32 in 9.416000 seconds pg_strtoint32_v2 in 8.099000 seconds (16.261267% faster) I was thinking that we should likely apply this before doing the hex literals, which is the main focus of [1]. The reason being is so that that patch can immediately have faster conversions by allowing the compiler to use bit shifting instead of other means of multiplying by a power-of-2 number. I'm hoping this removes a barrier for Peter from the small gripe I raised on that thread about the patch having slower than required hex, octal and binary string parsing. David [1] https://postgr.es/m/CAApHDvrL6_+wKgPqRHr7gH_6xy3hXM6a3QCsZ5ForurjDFfenA@mail.gmail.com [2] https://godbolt.org/z/7YoMT63q1
Вложения
В списке pgsql-hackers по дате отправления: