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