Use cases for IdentityHashMap

后端 未结 7 724
谎友^
谎友^ 2020-12-12 13:31

Could anyone please tell what are the important use cases of IdentityHashMap?

7条回答
  •  孤城傲影
    2020-12-12 14:12

    HashMap creates Entry objects every time you add an object, which can put a lot of stress on the GC when you've got lots of objects. In a HashMap with 1,000 objects or more, you'll end up using a good portion of your CPU just having the GC clean up entries (in situations like pathfinding or other one-shot collections that are created and then cleaned up). IdentityHashMap doesn't have this problem, so will end up being significantly faster.

    See a benchmark here: http://www.javagaming.org/index.php/topic,21395.0/topicseen.html

提交回复
热议问题