malte0811 / FerriteCore

MIT License
332 stars 26 forks source link

Regression in FastMap memory usage for blocks with no properties #131

Closed embeddedt closed 1 year ago

embeddedt commented 1 year ago

The change made in https://github.com/malte0811/FerriteCore/commit/130f29ca7428dced035dded4020abb419822cd06 (since 1.18) causes an Object2IntOpenHashMap to be allocated for every block, including ones with no properties. In a test scenario with 1 million property-less blocks, this seems to be using ~350MB of memory.

A simple fix is probably to have a static, empty Object2IntOpenHashMap instance that is used if the block contains no properties. However I am suspicious the change might still regress memory usage in the case of 1 or 2 properties as the Object2IntOpenHashMap is designed to be mutable, and likely has a higher memory footprint than the ImmutableMap (I have not measured this, though).

embeddedt commented 1 year ago

Related question: any reason not to use ImmutableList.copyOf(valuesList) here to avoid storing the extra ArrayList and unmodifiable wrapper objects?

https://github.com/malte0811/FerriteCore/blob/0bd73c6efb8efe6a4460894a978de96fa9ac4266/Common/src/main/java/malte0811/ferritecore/fastmap/FastMap.java#L53