New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shrink capacity in RateLimitStorage::remove_older_than
#3536
Conversation
ci ran out of space |
Ran out of space again |
// `shrink_to_fit` is not used because it would cause the capacity to be doubled when more capacity is needed | ||
if let Some(min_capacity) = map.len().checked_mul(2) { | ||
map.shrink_to(min_capacity); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So shrink_to_fit
apparently calls shrink_to(0)
internally. Then this code is used to keep some free capacity and avoid allocation when the map grows again. I dont think this is necessary, it smells like premature optimization because remove_older_than
is only caused once an hour. You can change this to use shrink_to_fit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* Shrink capacity in `RateLimitStorage::remove_older_than` * Update rate_limiter.rs * rerun ci * rerun ci * rerun ci * Update rate_limiter.rs
This prevents spikes in traffic from causing permanently increased memory usage.