Skip to content

Commit

Permalink
revert huge perf regression
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgotf committed Jun 22, 2023
1 parent 875b665 commit 9518b85
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions twilight-gateway/src/ratelimiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl CommandRatelimiter {

/// Waits for a permit to become available.
pub(crate) async fn acquire(&mut self) {
let now = poll_fn(|cx| self.poll_ready(cx)).await;
poll_fn(|cx| self.poll_ready(cx)).await;

self.instants.push(now + PERIOD);
self.instants.push(Instant::now() + PERIOD);
}

/// Polls for readiness.
Expand All @@ -89,9 +89,9 @@ impl CommandRatelimiter {
///
/// * `Poll::Pending` if the ratelimiter is full
/// * `Poll::Ready(now)` if the ratelimiter is ready for a new permit.
pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Instant> {
pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<()> {
if self.instants.len() != self.instants.capacity() {
return Poll::Ready(Instant::now());
return Poll::Ready(());
}

if !self.delay.is_elapsed() {
Expand All @@ -113,7 +113,7 @@ impl CommandRatelimiter {
self.instants.rotate_right(used_permits);
self.instants.truncate(used_permits);

Poll::Ready(now)
Poll::Ready(())
}
}
}
Expand Down

0 comments on commit 9518b85

Please sign in to comment.