cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Nef_3: Use sizeof(H) in Generic handle map

Open GilesBathgate opened this issue 2 years ago • 8 comments

Summary of Changes

~I believe this is correct, no two addresses can be closer than sizeof(void*) apart, and a handle usually is that size, but if it's bigger then dividing by a smaller size is ok. This helps pack the handles into the hash map more tightly.~

As suggested by @afabri this updates Generic handle map to divide the address of the handle by the size of the pointee. This should provide a better distribution in the hashmap.

Release Management

  • Affected package(s): Nef_3, Nef_S2
  • Issue(s) solved (if any): performance
  • License and copyright ownership: Returned to CGAL authors.

GilesBathgate avatar Apr 20 '22 20:04 GilesBathgate

I basically agree but I am wondering if we can go further. Usually we divide by the size of the pointee. @sloriot any idea how to achieve that.

afabri avatar Apr 21 '22 06:04 afabri

Also, although it does not really matter technically, it is not so much a question of tightness but about a better distribution in the hash map, I think.

afabri avatar Apr 21 '22 06:04 afabri

I basically agree but I am wondering if we can go further. Usually we divide by the size of the pointee. @sloriot any idea how to achieve that.

Because the map contains generic handles, I think the best you can do is divide by the smallest or you'll have overlapping addresses, but maybe that doesn't matter as it's just a collision? Perhaps the Generic hash map needs to have a Types... parameter and you can find the min/max sizeof at compile time? If you can divide by variable sizes, you can probably just pass that through to the hash functor.

Also, although it does not really matter technically, it is not so much a question of tightness but about a better distribution in the hash map, I think.

Yeah, that's basically what I mean, the table index ( k % table_size) when table_size is 32, will never be odd, if the k is even, meaning only half the buckets will get filled.

I think I understand now why prime numbers are good for the table size.

GilesBathgate avatar Apr 21 '22 07:04 GilesBathgate

@afabri The trouble with this approach I think is that the hashmap doesn't check the entries for equality, only the "hashes" of the entries. This works for handle addresses because they are unique (hence Unique_hash_map) but it doesn't work if you divide by the handle size, when the handle sizes differ, because you can get overlapping values.

GilesBathgate avatar Apr 29 '22 20:04 GilesBathgate

Successfully tested in CGAL-5.5-Ic-95

sloriot avatar May 31 '22 13:05 sloriot

I basically agree but I am wondering if we can go further. Usually we divide by the size of the pointee. @sloriot any idea how to achieve that.

@afabri So do you approve this PR and it can be integrated as is?

sloriot avatar Jun 16 '22 11:06 sloriot

ah I see that https://github.com/CGAL/cgal/pull/6560 replaces it. @GilesBathgate shall we close this PR ?

sloriot avatar Jun 16 '22 11:06 sloriot

@sloriot I am unsure about the right approach. I can close this draft if you want but I would rather leave it until the correct solution is merged.

GilesBathgate avatar Jun 16 '22 12:06 GilesBathgate