Repository navigation
Implement a custom Int2Int map for MapPalette - #1414
Conversation
|
Did a rough comparison with GrimAC which stores all the chunks sent to players. The heap dump I took before the patch shows 33% of the total chunk memory data was used by palettes. After the patch, the usage dropped to about 17%, resulting in about a 20% memory improvement per average chunk in my case. I'm aware they use a fork of packetevents so I applied the patch to their fork to test. Considering they seem to keep upstream commits up to date, I thought it'd be better to just merge the change here. |
booky10
left a comment
There was a problem hiding this comment.
Please refactor this new Map into a separate class (and mark it as @ApiStatus.Internal then)
Also, you mentioned copying existing libraries in your issue - was this copied from somewhere or did you write this on your own?
|
Mostly wrote it myself, but took great inspiration from https://github.com/aeron-io/agrona/blob/master/agrona/src/main/java/org/agrona/collections/Int2IntHashMap.java which should be compliant licensing-wise. The map should probably be renamed to something like UInt2UIntMap considering I chose to use -1 as the empty key value. |
…, simplify tableSizeFor
Stores key and value in one long to reduce array reads/writes Also improves resizing logic by removing unnecessary replacement logic check (Additionally also includes some minor code format changes)
|
Thanks for the PR and sorry that it took so long to merge! |
Replaces a very unnecessary HashMap<Object, Integer> with a much lighter custom Int2Int map.
Works fine from my tests, might warrant a unit test.
Closes #1412