WorldEdit icon indicating copy to clipboard operation
WorldEdit copied to clipboard

Refactor PlatformManager for performance

Open anonyco opened this issue 3 years ago • 2 comments

Two improvements sure to provide a nice speedup to WorldEdit:

  1. Desynchronize <PlatformManager>.queryCapability, which is used in some pretty tight loops that would feel the benefits of less synchronized.
  2. Remove the use of EnumMap from PlatformManager.preferences, which further optimizes <PlatformManager>.queryCapability because EnumMaps do incur some overhead, mostly from checking to make sure the enum you passed it is really of the same class as the enum of the EnumMap.

anonyco avatar Jul 23 '22 00:07 anonyco

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

me4502 avatar Jul 23 '22 01:07 me4502

I have significantly simplified these changes to the bare minimum: the removal of just the synchronized.

  1. 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?

  2. 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.

  1. 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.

anonyco avatar Jul 23 '22 13:07 anonyco