-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add caching of java classes/methods #186
Conversation
Signed-off-by: John Mazanec <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #186 +/- ##
=========================================
Coverage 82.78% 82.78%
Complexity 826 826
=========================================
Files 120 120
Lines 3631 3631
Branches 342 342
=========================================
Hits 3006 3006
Misses 468 468
Partials 157 157 Continue to review full report at Codecov.
|
@@ -195,7 +195,7 @@ jobjectArray knn_jni::nmslib_wrapper::QueryIndex(knn_jni::JNIUtilInterface * jni | |||
int resultSize = neighbors->Size(); | |||
|
|||
jclass resultClass = jniUtil->FindClass(env,"org/opensearch/knn/index/KNNQueryResult"); | |||
jmethodID allArgs = jniUtil->FindMethod(env, resultClass, "<init>", "(IF)V"); | |||
jmethodID allArgs = jniUtil->FindMethod(env, "org/opensearch/knn/index/KNNQueryResult", "<init>"); |
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.
Is this intended? We seem to still keep the class name?
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.
Yes, FindMethod is a wrapper defined in JNIUtil. We pass it the class name and the method name and it finds the method in the map.
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.
LGTM! Thanks
Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: John Mazanec <[email protected]> Signed-off-by: Martin Gaievski <[email protected]>
Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: John Mazanec [email protected]
Description
This PR adds Java class and method caching to both JNI libraries. FindClass/FindMethod functions can be expensive calls from C++ layer, so it is recommended to cache these values. For caching implementation, I followed this SO post answer. From a high level, the JNI_onLoad and JNI_onUnload methods will be called when the library is loaded/unloaded by the JVM. Here, we call an initialization function which sets up the caches.
gradle tests as well as google tests both pass.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.