On Fri, 24 May 2024 at 08:34, Andrew Dunstan <and...@dunslane.net> wrote: > That's all pretty nice! I'd take the win on this rather than wait for > some hypothetical patch that changes how output functions work.
On re-think of that, even if we changed the output functions to write directly to a StringInfo, we wouldn't get the same speedup. All it would get us is a better ability to know the length of the string the output function generated by looking at the StringInfoData.len before and after calling the output function. That *would* allow us to use the SIMD escaping, but not save the palloc/memcpy cycle for non-toasted Datums. In other words, if we want this speedup then I don't see another way other than this special case. I've attached a rebased patch series which includes the 3rd patch in a more complete form. This one also adds handling for varchar and char(n) output functions. Ideally, these would also use textout() to save from having the ORs in the if condition. The output function code is the same in each. Updated benchmarks from the test in [1]. master @ 7c655a04a $ for i in {1..3}; do pgbench -n -f bench.sql -T 10 -M prepared postgres | grep tps; done tps = 366.211426 tps = 359.707014 tps = 362.204383 master + 0001 $ for i in {1..3}; do pgbench -n -f bench.sql -T 10 -M prepared postgres | grep tps; done tps = 362.641668 tps = 367.986495 tps = 368.698193 (+1% vs master) master + 0001 + 0002 $ for i in {1..3}; do pgbench -n -f bench.sql -T 10 -M prepared postgres | grep tps; done tps = 430.477314 tps = 425.173469 tps = 431.013275 (+18% vs master) master + 0001 + 0002 + 0003 $ for i in {1..3}; do pgbench -n -f bench.sql -T 10 -M prepared postgres | grep tps; done tps = 606.702305 tps = 625.727031 tps = 617.164822 (+70% vs master) David [1] https://postgr.es/m/caaphdvplxwmzvbckcdgfu9xqjgcdm7tfprdtxub9pvgpnuy...@mail.gmail.com
v2-0001-Add-len-parameter-to-escape_json.patch
Description: Binary data
v2-0002-Use-SIMD-processing-for-escape_json.patch
Description: Binary data
v2-0003-Special-case-text-type-conversion-in-datum_to_jso.patch
Description: Binary data