Skip to content
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

Merged
merged 1 commit into from
Nov 7, 2021

Conversation

jmazanec15
Copy link
Member

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

  • Commits are signed as per the DCO using --signoff

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.

@codecov-commenter
Copy link

Codecov Report

Merging #186 (73c0ef1) into main (b68b5b3) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b68b5b3...73c0ef1. Read the comment docs.

@@ -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>");
Copy link
Member

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?

Copy link
Member Author

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.

@jmazanec15 jmazanec15 requested a review from vamshin November 6, 2021 18:25
Copy link
Member

@vamshin vamshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@jmazanec15 jmazanec15 merged commit 3fdae61 into opensearch-project:main Nov 7, 2021
@jmazanec15 jmazanec15 mentioned this pull request Nov 10, 2021
1 task
@jmazanec15 jmazanec15 added the Enhancements Increases software capabilities beyond original client specifications label Nov 15, 2021
martin-gaievski pushed a commit to martin-gaievski/k-NN that referenced this pull request Mar 7, 2022
martin-gaievski pushed a commit to martin-gaievski/k-NN that referenced this pull request Mar 7, 2022
Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: Martin Gaievski <[email protected]>
martin-gaievski pushed a commit to martin-gaievski/k-NN that referenced this pull request Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancements Increases software capabilities beyond original client specifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants