Skip to content

Commit

Permalink
refactor(gateway): avoid recent latencies rotate (#2396)
Browse files Browse the repository at this point in the history
[Rotate](https://github.com/rust-lang/rust/blob/37e74596c0b59e81b9ac58657f92297ef4ccb7ef/library/core/src/slice/rotate.rs)
is a perhaps surprisingly expensive operation, when we really just want
to move stuff one step to the right.

Inspired from a similar optimization in #2395 (tagged as a refactor
since this doesn't measurably impact performance).
  • Loading branch information
vilgotf authored Dec 26, 2024
1 parent 12e31c9 commit 4896c94
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion twilight-gateway/src/latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Latency {
self.periods += 1;

self.latency_sum += period_latency;
self.recent.rotate_right(1);
self.recent.copy_within(..Self::RECENT_LEN - 1, 1);
self.recent[0] = period_latency;
}

Expand Down

0 comments on commit 4896c94

Please sign in to comment.