Commit 24e19946 authored by Stepan Palamarchuk's avatar Stepan Palamarchuk Committed by Facebook Github Bot

Avoid duplicate call to steady_clock::now

Summary:
Currently we call `steady_clock::now` twice within just few instructions (one in `setScheduled` and one in `calcNextTick`) which adds unnecessary overhead.

This diff makes us call it only once and use it for both computation of the deadline and tick number.

This allows to achieve almost ~2x improvement in perf.

Reviewed By: jmswen, vitaut

Differential Revision: D13624360

fbshipit-source-id: 40bc3b3ad5123d22a5edcabd60d91c0f7efcbda7
parent 32236ec4
......@@ -51,12 +51,12 @@ HHWheelTimer::Callback::~Callback() {
void HHWheelTimer::Callback::setScheduled(
HHWheelTimer* wheel,
std::chrono::milliseconds timeout) {
std::chrono::steady_clock::time_point deadline) {
assert(wheel_ == nullptr);
assert(expiration_ == decltype(expiration_){});
wheel_ = wheel;
expiration_ = std::chrono::steady_clock::now() + timeout;
expiration_ = deadline;
}
void HHWheelTimer::Callback::cancelTimeoutImpl() {
......@@ -143,8 +143,9 @@ void HHWheelTimer::scheduleTimeout(
count_++;
callback->setScheduled(this, timeout);
auto nextTick = calcNextTick();
auto now = getCurTime();
auto nextTick = calcNextTick(now);
callback->setScheduled(this, now + timeout);
// There are three possible scenarios:
// - we are currently inside of HHWheelTimer::timeoutExpired. In this case,
......
......@@ -123,7 +123,9 @@ class HHWheelTimer : private folly::AsyncTimeout,
expiration_ - now);
}
void setScheduled(HHWheelTimer* wheel, std::chrono::milliseconds);
void setScheduled(
HHWheelTimer* wheel,
std::chrono::steady_clock::time_point deadline);
void cancelTimeoutImpl();
HHWheelTimer* wheel_{nullptr};
......
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