pgsql: pg_test_timing: Reduce per-loop overhead

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_test_timing: Reduce per-loop overhead
Date: 2026-04-02 00:49:26
Message-ID: E1w86FR-002X52-2d@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pg_test_timing: Reduce per-loop overhead

The pg_test_timing program was previously using INSTR_TIME_GET_NANOSEC on an
absolute instr_time value in order to do a diff, which goes against the spirit
of how the GET_* macros are supposed to be used, and will cause overhead in a
future change that assumes these macros are typically used on intervals only.

Additionally the program was doing unnecessary work in the test loop by
measuring the time elapsed, instead of checking the existing current time
measurement against a target end time. To support that, introduce a new
INSTR_TIME_ADD_NANOSEC macro that allows adding user-defined nanoseconds
to an instr_time variable.

While modifying the relevant code anyway, simplify it by not handling
durations <= 0 in test_timing(), since duration is unsigned and 0 is
disallowed by the caller.

Author: Lukas Fittl <lukas(at)fittl(dot)com>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Discussion: https://postgr.es/m/CAP53Pkyxv3-3gX+aOxC5tX0p2v9RHU+XH0iyvb64+ZnBXj92vg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/82c0cb4e672dbc89f0bd0013c625a3a16ee36ad6

Modified Files
--------------
src/bin/pg_test_timing/pg_test_timing.c | 28 ++++++++++++++--------------
src/include/portability/instr_time.h | 8 ++++++++
2 files changed, 22 insertions(+), 14 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2026-04-02 01:12:33 pgsql: Fix nocachegetattr() so it again supports deforming cstrings
Previous Message Andres Freund 2026-04-01 23:54:03 pgsql: read_stream: Prevent distance from decaying too quickly