greg7mdp / parallel-hashmap

A family of header-only, very fast and memory-friendly hashmap and btree containers.
https://greg7mdp.github.io/parallel-hashmap/
Apache License 2.0
2.47k stars 234 forks source link

Avoid Memory Reallocations in flat_hash_map clear for Trivial Classes #205

Closed linjiahao962889027 closed 1 year ago

linjiahao962889027 commented 1 year ago

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 commented 1 year ago

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

greg7mdp commented 1 year ago

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

linjiahao962889027 commented 1 year ago

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