pgsql: Speed up printing of integers in snprintf.c.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Speed up printing of integers in snprintf.c.
Date: 2021-10-28 17:40:03
Message-ID: E1mg9Nj-00016y-OB@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Speed up printing of integers in snprintf.c.

Since the only possible divisors are 8, 10, and 16, it doesn't cost
much code space to replace the division loop with three copies using
constant divisors. On most machines, division by a constant can be
done a lot more cheaply than division by an arbitrary value.
A microbenchmark testing just snprintf("foo %d") with a 9-digit value
showed about a 2X speedup for me (tgl). Most of Postgres isn't too
dependent on the speed of snprintf, so that the effect in real-world
cases is barely measurable. Still, a cycle saved is a cycle earned.

Arjan van de Ven

Discussion: https://postgr.es/m/40a4b32a-b841-4667-11b2-a0baedb12714@linux.intel.com
Discussion: https://postgr.es/m/6e51c644-1b6d-956e-ac24-2d1b0541d532@linux.intel.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3c17926eedd51c4094db7c62f59950918044ab1c

Modified Files
--------------
src/port/snprintf.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2021-10-29 01:45:34 pgsql: Speed up TAP tests of pg_receivewal
Previous Message Tom Lane 2021-10-28 15:45:35 pgsql: Improve contrib/amcheck's tests for CREATE INDEX CONCURRENTLY.