From 68efba44e84c9b58da123dfcbc10b5fa60e96bd9 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Wed, 1 Mar 2023 10:17:01 -0700 Subject: [PATCH] Slight performance improvements before calling APIHooks::clear --- proxy/InkAPIInternal.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h index 572a223b124..d4bdf389498 100644 --- a/proxy/InkAPIInternal.h +++ b/proxy/InkAPIInternal.h @@ -203,14 +203,24 @@ template FeatureAPIHooks::~FeatureAPIHooks() this->clear(); } +// The APIHooks::clear() method can't be inlined (easily), and we end up calling +// clear() very frequently (it's used in a number of features). A rough estimate +// is that we may call APIHooks::clear() as much as 230x per transaction (there's +// 180 additional APIHooks that should be eliminated in a different PR). This +// code at least avoids calling this function for a majority of the cases. +// Before this code, APIHooks::clear() would show up as top 5 in perf top. template void FeatureAPIHooks::clear() { - for (auto &h : m_hooks) { - h.clear(); + if (m_hooks_p) { + for (auto &h : m_hooks) { + if (!h.is_empty()) { + h.clear(); + } + } + m_hooks_p = false; } - m_hooks_p = false; } template