-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(gateway): optimize
CommandRatelimiter
size (#2395)
Switches from storing absolute timestamps to relative ones to `delay` as milliseconds (tokio's timer resolution). This reduces the item size from 12 bytes to just 2 (as 60,000 ms fits in a `u16`) and adds a negligible amount of bookkeeping work in rebasing the timestamps on `delay` elapsing. From this I also made the first relative timestamp implicit from whether `delay` is elapsed or not (instead of being zero). Additionally, this PR fixes the following minor bugs: * always store waker in `poll_pending` (always call `Sleep::poll`) * `slice::partition_point` may return any matching element, but we depend upon the first being returned (it should be impossible to acquire two permits at the same time in practice, since we send a gateway command between each acquisition) * `Vec::with_capacity` being allowed to allocate more than the requested amount whereas we require the amount to be exact (the current implementation is exact, however) TODO: - [x] Update doc comments - [x] ~~Explain algorithm more in code comments, the logic is complex~~ split logic into self-explanatory methods - [x] add more tests for new edge cases. --------- Co-authored-by: Erk <[email protected]>
- Loading branch information
Showing
2 changed files
with
111 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters