Skip to content

Commit 782fbfd

Browse files
committed
Slight performance improvements before calling APIHooks::clear (#9480)
(cherry picked from commit c54a2e2)
1 parent c2651a1 commit 782fbfd

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

proxy/InkAPIInternal.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,24 @@ template <typename ID, int N> FeatureAPIHooks<ID, N>::~FeatureAPIHooks()
197197
this->clear();
198198
}
199199

200+
// The APIHooks::clear() method can't be inlined (easily), and we end up calling
201+
// clear() very frequently (it's used in a number of features). A rough estimate
202+
// is that we may call APIHooks::clear() as much as 230x per transaction (there's
203+
// 180 additional APIHooks that should be eliminated in a different PR). This
204+
// code at least avoids calling this function for a majority of the cases.
205+
// Before this code, APIHooks::clear() would show up as top 5 in perf top.
200206
template <typename ID, int N>
201207
void
202208
FeatureAPIHooks<ID, N>::clear()
203209
{
204-
for (auto &h : m_hooks) {
205-
h.clear();
210+
if (m_hooks_p) {
211+
for (auto &h : m_hooks) {
212+
if (!h.is_empty()) {
213+
h.clear();
214+
}
215+
}
216+
m_hooks_p = false;
206217
}
207-
m_hooks_p = false;
208218
}
209219

210220
template <typename ID, int N>

0 commit comments

Comments
 (0)