Aust1n46 / VentureChat

GNU General Public License v3.0
37 stars 47 forks source link

Cache method handle in Format #62

Open MrMks opened 1 year ago

MrMks commented 1 year ago
Aust1n46 commented 1 year ago

I always appreciate any contribution so thank you.

I do have to ask what are we discussing for the performance? Are there performance issues that warrant the changes?

It does add complexity to an already complex workflow. And I would have to refactor all of these changes to the 4.0 dev branch.

MrMks commented 1 year ago

You are right, Java 17 is a good choice, but I'm using a bukkit on forge server(named CatServer) and older forge don't support newer Java, so it is hard for me to migrate to Java 17.

About the performance issue, it seems like that getMethod runs a caller check behind, and the check cost a lot of time. I found this in one spark profiler.

Call setAccessible(true) on Method instances and then cache them can bring us a better performance, in this case, we can reduce the times of caller check.

Going further, if we use MethodHandle in a proper way, we may get the best performance. Java's c1 and c2 compiler will inline frequently used and immutable handles, as the result, it runs like we directly call those methods.

p.s. my English is bad, there may be many wrongs in my sentences. If it is really hard to understand what I mean, I'd like to use a translator then.