On Fri, 8 Dec 2023 at 12:13, Nathan Bossart <nathandboss...@gmail.com> wrote: > Here's a patch that removes a couple of strlen() calls that showed up > prominently in perf for a COPY TO (FORMAT json) on 110M integers. On my > laptop, I see a 20% speedup from ~23.6s to ~18.9s for this test.
+ seplen = use_line_feeds ? sizeof(",\n ") - 1 : sizeof(",") - 1; Most modern compilers will be fine with just: seplen = strlen(sep); I had to go back to clang 3.4.1 and GCC 4.1.2 to see the strlen() call with that code [1]. With: if (needsep) - appendStringInfoString(result, sep); + appendBinaryStringInfo(result, sep, seplen); I might be neater to get rid of the if condition and have: sep = use_line_feeds ? ",\n " : ","; seplen = strlen(sep); slen = 0; ... for (int i = 0; i < tupdesc->natts; i++) { ... appendBinaryStringInfo(result, sep, slen); slen = seplen; ... } David [1] https://godbolt.org/z/8dq8a88bP