4 ms·
Byte Buddy is quite efficient. It is more or less like implementing Java code per hand. Byte Buddy comes along with a benchmark where the results are listed her
by raphw 12y ago
Byte Buddy is quite efficient. It is more or less like implementing Java code per hand. Byte Buddy comes along with a benchmark where the results are listed here: http://bytebuddy.net/#/tutorial http://bytebuddy.net/#/tutorial
This way, it even beats the use of MethodHandles for accessing fields which still have a slight overhead over "normal" field access: https://gist.github.com/raphw/881e1745996f9d314ab0 https://gist.github.com/raphw/881e1745996f9d314ab0
Of course, there might be a flaw in the benchmark, those are tricky. Si please challange it, I am always interested in such details. I also guess, that the advantage will decrease with future JVMs.
- the8472 12y agoAfaik method handles need to be assigned to final fields (with -XX:+TrustFinalNonStaticFields) or final static fields for the JIT to be able to inline them.
- raphw 12y agoYou are right, it is stated here: https://wiki.openjdk.java.net/display/HotSpot/Deconstructing+MethodHandles https://wiki.openjdk.java.net/display/HotSpot/Deconstructing... I will update and rerun the benchmark some time. Unfortunately, storing a value in a static final field allows the VM to pre-determine the entire method call and to erase the invocation altogether. This makes it hard to measure the impact of the method call. It is also questionable if this is the desired measurement as reflection is normally used to delay a call site determination to runtime which could not be done using a MethodHandle in a static final field. But really good catch! I will hava a look at it some time soon.