From 91d61b8c9a60f0e19b73e03c1a0e46d2dc64573d Mon Sep 17 00:00:00 2001 From: Jianghua Yang Date: Thu, 27 Mar 2025 01:58:58 +0800 Subject: [PATCH] Use CLOCK_MONOTONIC_COARSE for instr_time when available This patch modifies `instr_time.h` to prefer `CLOCK_MONOTONIC_COARSE` when available. `CLOCK_MONOTONIC_COARSE` provides a lower resolution but faster alternative for timing operations, which can reduce the overhead of frequent timestamp retrievals. On macOS, `CLOCK_MONOTONIC_RAW` remains the preferred choice when available, as it provides high-resolution timestamps. Otherwise, `CLOCK_MONOTONIC` is used as a fallback. Author: Jianghua Yang --- src/include/portability/instr_time.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h index a6fc1922f20..4b61c2fddc4 100644 --- a/src/include/portability/instr_time.h +++ b/src/include/portability/instr_time.h @@ -98,7 +98,9 @@ typedef struct instr_time * CLOCK_MONOTONIC_RAW which is both faster to read and higher resolution than * their version of CLOCK_MONOTONIC. */ -#if defined(__darwin__) && defined(CLOCK_MONOTONIC_RAW) +#ifdef CLOCK_MONOTONIC_COARSE +#define PG_INSTR_CLOCK CLOCK_MONOTONIC_COARSE +#elif defined(__darwin__) && defined(CLOCK_MONOTONIC_RAW) #define PG_INSTR_CLOCK CLOCK_MONOTONIC_RAW #elif defined(CLOCK_MONOTONIC) #define PG_INSTR_CLOCK CLOCK_MONOTONIC -- 2.25.1