Closed maarzt closed 3 years ago
@tpietzsch There is much room for improvement still:
Both changes combined would remove all jave object header overhead in LabelMapping.
@maarzt Nice!
As I suspected, making the object/id bimap thread-safe is a problem.
The synchronization you put in is not sufficient.
In particular, it is not safe to call labelToId.get(object)
while a concurrent labelToId.put(object, id)
is happening.
It is not guaranteed that the get()
will see the state either before or after the put()
. It might see something else (looking at the source code of TObjectIntHashMap
).
I think it might be ok to just synchronize every access to the bimap. I'll go over it again.
I revised it a bit, and synchronizing every access to the bimap doesn't seem to make a difference. Neither for LabelingBenchmark
nor for the use case in metaseg
.
This PR contains many ideas to improve the performance of LabelingMapping.
Changes by @tpietzsch
Changes by @maarzt
SortedInts
has a much better hash code, improving the performance of the internedSet Hashmap.