Costs of caught exceptions during method handle resolve

Jan Bernitt jaanbernitt at gmail.com
Fri Aug 9 11:15:38 UTC 2024


Hi everyone!

I recently found a performance issue in my library that goes back to large
numbers of exceptions being thrown and caught where the costs are dominated
by filling in the stack trace and resolving method handles.

So I investigated ways to avoid causing the exceptions. One of the reasons
for the exceptions
was somewhere internally in the method handle resolve. I ended up caching
the method handles to avoid this happening over and over again as my
library uses method handles all the time :D

As far as I can tell this should be something the JDK can solve differently
internally to avoid the cost of throwing and catching the exception which
should improve performance of method handles significantly if you use them
(including the lookup) in a hot loop. You can find more details here
https://github.com/dhis2/json-tree/pull/66

If this is of interest to some feel free to ask for more details.
Also if anyone sees that I am just using methods handles wrong and
therefore cause the internal exception please let me know.

Best
Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/discuss/attachments/20240809/7e2aa54f/attachment.htm>


More information about the discuss mailing list