Implementation of LockFreeHashMap with Open Addressing #763
Replies: 3 comments 1 reply
-
Hello,
I think insertion is not the main problem, it is the retrieval in
I'm not sure what the double linked list is for? W.r.t. Organ Piping / Smart Search: These have the disadvantage that you search through memory in a non linear fashion, so it is likely that they will have the same cache miss problems as the separate chaining mechanism that I'm using now. |
Beta Was this translation helpful? Give feedback.
-
Hi @jrouwe
Will remove the concept of objects within a bucket, will have buckets which will have only one object. This can be done via Linear probing if there is a collision while insertion, use robin hood method for insertion. The bytes block is previously allocated. In this case values with same inKeyHash would be around the same memory and could have a cache hit probably. But unsure whether it would be Lock Free. since with the existing solution the whole bucket (initial bucket address) will be locked for find() and create() where we can append objects to the beginning of the linked list
While allocating within LFHMallocatorContext, if a KV with a fresh inKeyHash has been found allocate with bytes for the same and skip of some extra memory which can accomodate 15-30 objects for the next KV insertion (which will have a different inKeyHash). Keep track of the begin and end for each KV and in case if another KV with same inKeyHash is available allocate memory from the skipped memory after similar inKeyHash is written (can fetch the mBegin from mBuckets if similar inKeyHash was inserted). By this method we can try to bring elements with same inKeyHash closer in the memory. Current implementation does add elements contiguously where nextOffset of each KV would point a different location, we do have cache misses here. Also traced the number of objects within a bucket, tested for multiple examples with Linear and Discrete movements with Performance Testing which is not exceeding 9 objects per bucket As suggested open addressing might not be feasible since inKeyHash (only common factor between find() and create()) would be the input for the same and will result in the same index. Would check if this library be feasible in our case |
Beta Was this translation helpful? Give feedback.
-
I think this is what we have been discussing all the time right?
The physics simulation uses all CPU cores to read/write things to that cache at the same time. Any sort of lock will remove most of the parallelism and probably kill performance.
I'm not sure if I understand the question. The only reason why that allocator exists is that all threads are hammering the map at the same time. It was using a single atomic ('next free byte') at first but this atomic was hammered so much that it slowed down the whole system, so now the allocator only touches the atomic to get a larger block in which it can then put a number of keys. If you get rid of chaining and put everything in the hash map directly you won't have that problem anymore. You will have other problems though:
Jolt is currently built without the use of any 3rd party libraries, I would prefer to keep it that way. Of course, you can do a test integration to see if it would help speed up things, but I wouldn't accept a PR that introduces the library. |
Beta Was this translation helpful? Give feedback.
-
Hi @jrouwe, the current lockfreehashmap implementation in the code id done with Separate chaining with a linked list structure and we had a couple of ideas for optimization for the same and would like to have your thoughts on the same.
Beta Was this translation helpful? Give feedback.
All reactions