Refactor PlatformManager for performance
Two improvements sure to provide a nice speedup to WorldEdit:
- Desynchronize
<PlatformManager>.queryCapability, which is used in some pretty tight loops that would feel the benefits of lesssynchronized. - Remove the use of
EnumMapfromPlatformManager.preferences, which further optimizes<PlatformManager>.queryCapabilitybecauseEnumMaps do incur some overhead, mostly from checking to make sure theenumyou passed it is really of the same class as theenumof theEnumMap.
Refactors for performance that make the code substantially messier (the fact you didn't follow the style guide at all aside), without any proof of speed-up or evidence that it's necessary, won't be accepted.
Provide a microbenchmark and CPU profile that show why these changes make sense to do if you want to PR something like this.
I'm also not convinced it couldn't be done in a substantially cleaner manner, if it's true that this has a performance impact
I have significantly simplified these changes to the bare minimum: the removal of just the synchronized.
-
I was unaware that there was a style guide. I read all the markdown and txt files, including CONTRIBUTING.md. Could you refer me to where to find the style guide?
-
The results of my microbenchmark are below:
Before:
Calculated BlockType.getRichName x10000 in 84128654ns
Calculated BlockType.getRichName x10000 in 14269327ns
Calculated BlockType.getRichName x10000 in 7806132ns
After:
Calculated BlockType.getRichName x10000 in 60178043ns
Calculated BlockType.getRichName x10000 in 7953745ns
Calculated BlockType.getRichName x10000 in 4852244ns
Across the runs above, we see 40%-79% better performance for BlockType.getRichName with this small change.
- I am very unfamiliar with the available Java tools and do not know "CPU profile." I am not asking you to waste your time explaining every step to me, rather I would really appreciate it if you could give me a piece of text or a name of a software/tool that I could look up and research to learn more about what the common way to do this is in the WorldEdit project.
Many thanks for your time and attention to this.