diff --git a/README.md b/README.md index 1e562ba..c7b9b5f 100644 --- a/README.md +++ b/README.md @@ -204,10 +204,14 @@ template Still, this is a pretty good result, we are now inserting values into our parallel_hash_map three times faster than we were able to do using the flat_hash_map, while using a lower memory ceiling.

Using the intrinsic parallelism of the parallel_hash_map with internal mutexes

It may not be practical to add logic into your program to ensure you use different internal submaps from each thread. Still, locking the whole parallel_hash_map for each access would forego taking advantage of its intrinsic parallelism.

-

For that reason, the parallel_hash_map provides optional internal locking using the absl::Mutex (the default template parameter is absl::NullMutex, which does no locking and doesn't have any extra size cost). When selecting absl::Mutex, one mutex is created for each internal submap at a cost of 8 bytes per submap.

+

For that reason, the parallel_hash_map can provide internal locking using the absl::Mutex (the default template parameter is absl::NullMutex, which does no locking and has no size cost). When selecting absl::Mutex, one mutex is created for each internal submap at a cost of 8 bytes per submap.

@@ -268,6 +268,9 @@ class Mutex = absl::NullMutex> // use absl::Mutex to enable internal locks class parallel_flat_hash_map; +

Let's see what result we get for the insertion of random values from multiple threads, however this time we create a parallel_hash_map with internal locking, and modify the code so that each thread can insert values in any submap (no pre-selection).

+

no_preselection

+

flat_par_mutex_4

In Conclusion

We have seen that the novel parallel hashmap approach, used within a single thread, provides significant space advantages, with a very minimal time penalty. When used in a multi-thread context, the parallel hashmap still provides a significant space benefit, in addition to a consequential time benefit by drastically reducing (or even eliminating) lock contention when accessing the parallel hashmap.

Thanks