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

Avoid Memory Reallocations in flat_hash_map clear for Trivial Classes #205

Closed
linjiahao962889027 opened this issue Aug 11, 2023 · 3 comments

Comments

@linjiahao962889027
Copy link

Description:
When both the Key and Value types are trivial classes, I suggest modifying the behavior of clear in flat_hash_map to avoid releasing memory, similar to the behavior of std::vector. The current reallocation during clear impacts performance due to the second allocation, especially for trivial types where memory deallocation isn't necessary. This change would align the behavior with other standard containers, providing better performance for scenarios where frequent clearing is required.

@greg7mdp
Copy link
Owner

Thanks @linjiahao962889027, this is a good suggestion, I'll look into it.

@greg7mdp
Copy link
Owner

greg7mdp commented Sep 2, 2023

Hey @linjiahao962889027 , this should fix your issue, please let me know if you see any problem.

@linjiahao962889027
Copy link
Author

Hey @linjiahao962889027 , this should fix your issue, please let me know if you see any problem.
Awesome!!! It seems very great!!!

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

No branches or pull requests

2 participants