From 5fc220ce4ed8406e7c6852c6a6c59fb74a6e3f82 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 17 Jun 2022 12:51:20 -0700
Subject: [PATCH v2 1/4] Add already-disabled fastpath to disable_timeout().

Otherwise callers that might call disable_timeout() frequently need to check
get_timeout_active() to avoid GetCurrentTimestamp() and other overheads in
disable_timeout().

Needed to avoid get_timeout_active() check in the subsequent commit fixing a
small performance regression.
---
 src/backend/utils/misc/timeout.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 6f5e08bc302..d1219afa614 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -692,6 +692,11 @@ disable_timeout(TimeoutId id, bool keep_indicator)
 	Assert(all_timeouts_initialized);
 	Assert(all_timeouts[id].timeout_handler != NULL);
 
+	/* fast path for an already disabled timer */
+	if (!all_timeouts[id].active &&
+		(!all_timeouts[id].indicator || keep_indicator))
+		return;
+
 	/* Disable timeout interrupts for safety. */
 	disable_alarm();
 
-- 
2.35.1.677.gabf474a5dd

