Skip to content

Commit 585ba5f

Browse files
committed
perf(body): reuse read timeout timer
1 parent aa0063a commit 585ba5f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/client/layer/timeout/body.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@ where
221221
// Poll the actual body
222222
match ready!(this.body.poll_frame(cx)) {
223223
Some(Ok(frame)) => {
224-
// Reset timeout on successful read
225-
this.sleep.set(None);
224+
// Reuse the sleep to avoid allocating and registering a new timer for every frame.
225+
if let Some(sleep) = this.sleep.as_mut().as_pin_mut() {
226+
let deadline = this.timer.now() + *this.timeout;
227+
this.timer.reset(sleep.get_mut(), deadline);
228+
}
226229
Poll::Ready(Some(Ok(frame)))
227230
}
228231
Some(Err(err)) => Poll::Ready(Some(Err(err.into()))),

0 commit comments

Comments
 (0)