Commit 750d49c8 authored by Chad Parry's avatar Chad Parry Committed by facebook-github-bot-0

Avoid cost of cancelAll

Summary:
This is an experimental diff that may improve the performance of `HHWheelTimer::cancelAll`. If there are no timers to cancel, then it can bail early.

Since perflab is unlikely to be conclusive, and since this diff looks like a strict improvement, I'll proceed with landing it.

Reviewed By: djwatson

Differential Revision: D2735297

fb-gh-sync-id: 9f5a811ee6d9fa9434576e9abd3ef3443a7579b7
parent 5ff51e97
...@@ -218,6 +218,9 @@ void HHWheelTimer::timeoutExpired() noexcept { ...@@ -218,6 +218,9 @@ void HHWheelTimer::timeoutExpired() noexcept {
} }
size_t HHWheelTimer::cancelAll() { size_t HHWheelTimer::cancelAll() {
size_t count = 0;
if (count_ != 0) {
decltype(buckets_) buckets; decltype(buckets_) buckets;
// Work around std::swap() bug in libc++ // Work around std::swap() bug in libc++
...@@ -233,8 +236,6 @@ size_t HHWheelTimer::cancelAll() { ...@@ -233,8 +236,6 @@ size_t HHWheelTimer::cancelAll() {
std::swap(buckets, buckets_); std::swap(buckets, buckets_);
#endif #endif
size_t count = 0;
for (auto& tick : buckets) { for (auto& tick : buckets) {
for (auto& bucket : tick) { for (auto& bucket : tick) {
while (!bucket.empty()) { while (!bucket.empty()) {
...@@ -245,6 +246,7 @@ size_t HHWheelTimer::cancelAll() { ...@@ -245,6 +246,7 @@ size_t HHWheelTimer::cancelAll() {
} }
} }
} }
}
return count; return count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment