Skip to content
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

Merged
merged 7 commits into from Jul 10, 2023

Conversation

dullbananas
Copy link
Collaborator

This prevents spikes in traffic from causing permanently increased memory usage.

@dullbananas
Copy link
Collaborator Author

ci ran out of space

@dullbananas
Copy link
Collaborator Author

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);
}
Copy link
Member

@Nutomic Nutomic Jul 10, 2023

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Nutomic Nutomic merged commit 73492af into LemmyNet:main Jul 10, 2023
1 check passed
Nutomic pushed a commit that referenced this pull request Jul 21, 2023
* Shrink capacity in `RateLimitStorage::remove_older_than`

* Update rate_limiter.rs

* rerun ci

* rerun ci

* rerun ci

* Update rate_limiter.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants