robin-map icon indicating copy to clipboard operation
robin-map copied to clipboard

The memory usage increases sharply

Open inabao opened this issue 1 month ago • 2 comments

In versions v1.4.0 and v1.2.0 compared to v1.0.1, when I use robin_map and insert a very large value as a key, the memory consumption increases sharply.

inabao avatar Nov 05 '25 07:11 inabao

You can generate large keys using the following code:

std::vector<int64_t> ids(count);
for (int64_t i = 0; i < count; ++i) {
    ids[i] = (i << 48); 
}

inabao avatar Nov 05 '25 09:11 inabao

Do you use the identity hash function? That would create a lot of collisions with the default map, which uses a power of two for the size of the table, using the keys you insert. Can you try tsl::robin_pg_map or with another hash function?

See the second paragraph of the README:

Four classes are provided: tsl::robin_map, tsl::robin_set, tsl::robin_pg_map and tsl::robin_pg_set. The first two are faster and use a power of two growth policy, the last two use a prime growth policy instead and are able to cope better with a poor hash function. Use the prime version if there is a chance of repeating patterns in the lower bits of your hash (e.g. you are storing pointers with an identity hash function). See GrowthPolicy for details.

Tessil avatar Nov 09 '25 11:11 Tessil