ProjectKig / KigPaper

Paper 1.8.8 fork with critical performance tweaks, bug fixes and gameplay improvements.
https://playkig.com
43 stars 11 forks source link

metadata: add better BlockMetadataStore #14

Closed roccodev closed 2 years ago

roccodev commented 2 years ago

This adds a drop-in alternative to CraftBukkit's BlockMetadataStore, aiming to reduce memory footprint and increase performance.

Here are some benchmark results from my machine (Ryzen 5 3600 @ 3.6 GHz, 3200 MHz RAM), with regular warmup/measurement iterations but only one fork. (YMMV)

Operation Old (op/s) New (op/s) Delta
get 341,332 ± 5,531 3,224,111 ± 148,786 +944%
contains 315,856 ± 32,095 3,050,975 ± 362,347 +965%
insert 257,185 ± 4,249 797,096 ± 152,187 +309%
remove 327,822 ± 36,262 3,173,584 ± 758,450 +968%

Additionally, for a table of 20 blocks with one metadata pair each, there is a 20% size decrease. (5.9 KB -> 4.7 KB)

You can run benchmarks using these commands:

mvn compile -P benchmarks
mvn package -P benchmarks

java -jar Benchmarks/target/paper-benchmarks.jar

(The first two commands are hit-or-miss sometimes, if you get compilation errors just try again)

I had originally planned to use a primitive collection (TIntObjectHashMap), though that required an extra map inside. I think it's only justified if many metadata pairs are created for one block, to get better hash performance.

It's worth noting that this also adds Mockito as a test dependency on paperspigot-server, as per your suggestion.

andreasdc commented 2 years ago

Same for player metadata maybe?

roccodev commented 2 years ago

We've already replaced most other metadata stores with simple maps that are stored in the entity instance, so that's not needed.

andreasdc commented 2 years ago

We've already replaced most other metadata stores with simple maps that are stored in the entity instance, so that's not needed.

Which patch?

andreasdc commented 2 years ago

We've already replaced most other metadata stores with simple maps that are stored in the entity instance, so that's not needed.

This one? https://github.com/ProjectKig/KigPaper/blob/ver/1.8.8/Spigot-Server-Patches/0200-Change-metadata-to-be-non-global.patch Is this better in performance?