Re: micro-optimizing json.c
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: Nathan Bossart <nathandbossart@gmail.com>, Joe Conway
<mail@joeconway.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Andrew Dunstan <andrew@dunslane.net>,
Davin Shearer <davin@apache.org>, PostgreSQL-development
<pgsql-hackers@postgresql.org>
Date: 2023-12-07T23:43:47Z
Lists: pgsql-hackers
On Thu, 2023-12-07 at 17:12 -0600, Nathan Bossart 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. Nice improvement. The use of (len = ...) in a conditional is slightly out of the ordinary, but it makes the conditionals a bit simpler and you have a comment, so it's fine with me. I wonder, if there were an efficient cast from numeric to text, then perhaps you could avoid the strlen() entirely? Maybe there's a way to use a static buffer to even avoid the palloc() in get_str_from_var()? Not sure these are worth the effort; just brainstorming. In any case, +1 to your simple change. Regards, Jeff Davis
Commits
-
Micro-optimize datum_to_json_internal() some more.
- 0d1adae6f739 17.0 landed
-
Micro-optimize JSONTYPE_NUMERIC code path in json.c.
- dc3f9bc549d4 17.0 landed