-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make the event system use MethodHandles instead of reflections for calling events #3916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Java 21 results |
| <version>1.0</version> | ||
| </signature> | ||
| <ignores> | ||
| <!-- Allow using MethodHandle APIs even if the signature implies they don't exist --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What versions do they exist in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signatures are polymoprhic (esp. the invoke methods, they "appear" as varargs, but they are special) and iirc the tool can't handle that.
|
Can you include the benchmark? |
This is the code i used to compare normal vs reflections vs methodHandle |
|
Is there a way to include it in the build like junit? |
|
I'm not sure if it will still be a reliable result if it's integrated into the build process. But i can add it and have a look |
|
@md-5 done |
|
The benchmark should include usage of Blackhole in |
|
like this? |
Does this close the gap between direct invocation and reflection/methodhandle in the benchmark? |
|
|
So apparantly no relative change. Either way it should be correct to have it in there. |
|
I am thinking about just create an Consumer with a LambdaMetafactory at this point, as i remember @Janmm14, you already did that once but with more changes, where those other changes necessary? Those would be the the result for consumers with lambda btw Edit: i have taken a look, was for having the correct classloaders otherwise it won't work, so using consumers is not that easy, and i'd stick to MethodHandles |
It's wild that I assumed MethodHandles would be optimized to use invokedynamic, achieving performance similar to lambdas, but it seems that's not the case. Have you tested directly looking up method handles (instead of using unreflect) or privileged-level lookup? |
I have tested it, looks like its exactly the same |
How a method handle is retrieved shouldn't change its invoke performance anyway. |
I really think my latest attempt in #3114 is already looking like a quite good impl of that, yes it is a somewhat bigger change, but still very contained. Edit: Maybe some1 can think of an even easier way of collecting class loaders of event listeners? Edit 2: Now as I look at that code, I think there's no need to collect the plugin classloaders, just collect the class loaders of all event listeners and it should work. |
|
I do another benchmark, calling a setName(String) to simply set a property instead of an empty method, and obtained significantly different results. Platform: EPYC 9374F+Debian12+jdk25 Test code: |
|
your results pretty much look all the same speed, maybe because you dont use blackholes? i guess the results cannot be correct |
|
Yes, I think the jvm can optimize this way easier, because of the static argument and no indirection of the object itself. Blackhole is used on the resulting object (by returning it), but you want to measure an actual method invocation process, thats why blackhole should be used inside the resulting method, maybe you could also instead use Additionally a setup method per invocation an be very inaccurate for such a tiny micro benchmark, which can be seen in your result at those huge +/- errors. Edit: There's no need to use a setup method at all here additionally. |
You're right, if I remove setup(), the running speed of all methods will become slower, and the gap between them will become larger. MethodHandle is about 2x fast as Reflection, and direct call is about 5x fast as MethodHandle. |
No description provided.