pgsql: Speedup pg_strtok() with a static lookup table

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Speedup pg_strtok() with a static lookup table
Date: 2026-11-26 04:56:03
Message-ID: E1xWRWd-00000000LoE-1eOp@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Speedup pg_strtok() with a static lookup table

This function has been known to be slow for a while and a redesign is
probably on the cards. Meanwhile, let's try to squeeze a little more
performance out of it.

Here we define a 256-byte lookup table to specify character classes and
use that in the function rather than writing long and complex
expressions to get the same thing.

A benchmark showed pg_upgrade performing about 5% faster with this
change when restoring the database schemas into the new cluster, so more
of an evolution than a revolution.

Author: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: David Steele <david(at)pgbackrest(dot)org>
Discussion: https://postgr.es/m/CAApHDvo-YKLqfHfjrCFJCBxMXni83Xsfn6Nbe79CWspCHKta_Q@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/56227fd51c452624b1c08947e4ed910a8d78748e

Modified Files
--------------
src/backend/nodes/read.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2026-11-26 05:52:37 pgsql: Fix assorted issues in conflict log table handling.
Previous Message David Rowley 2026-11-26 04:16:07 pgsql: Fix incorrect data type in pg_terminate_backend()