Skip to content

Conversation

@qmdx
Copy link
Contributor

@qmdx qmdx commented Jan 30, 2026

Added reflection performance optimization for MethodInvoker.java, modified to use MethodHandles instead of Reflection.

1,Invocation.java list targetClasses change set. Gain higher performance

2,Compatible with JDK 8 reflection

Reflection vs MethodHandles API in Java: Performance, Use Cases, and Best Practices
https://prgrmmng.com/reflection-vs-methodhandles-api-java


Method time
directCall ~1 ns
methodHandleExact ~2–4 ns
methodHandleInvoke ~4–8 ns
reflectionCall ~15–30 ns
Resolve reflective metadata at startup, convert it to MethodHandles, and eliminate reflection from the hot path.
Approach Relative Cost Notes
Direct field access Baseline
MethodHandle getter 1.2× JIT inlineable
Method call via reflection 6–10× Access checks + JNI
Field.get() 8–15× Worst case

@harawata
Copy link
Member

harawata commented Feb 7, 2026

Hello @qmdx ,

Thank you for the PR.
I haven't looked into the details, but MyBatis 3.6.x will require Java 17, so please remove the Java 8 compatibility part of the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants