-
Notifications
You must be signed in to change notification settings - Fork 239
Cache JNI jClass jfieldID lookups #314
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
Conversation
@smirnoal can you take a look at this? |
CHECK_EXCEPTION(env, env->SetLongField(invocationRequest, deadlineTimeInMsField, std::chrono::duration_cast<std::chrono::milliseconds>(response.deadline.time_since_epoch()).count())); | ||
|
||
if(response.xray_trace_id != ""){ | ||
CHECK_EXCEPTION(env, xrayTraceIdField = env->GetFieldID(invocationRequestClass , "xrayTraceId", "Ljava/lang/String;")); | ||
if(xrayTraceIdField == nullptr){ |
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.
why are these conditions needed for xrayTraceIdField
, clientContextField
, cognitoIdentityField
?
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.
@smirnoal Not all next responses contain them, so it would be more efficient to load them lazily than eagerly. Note that they are still cached once they are loaded.
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.
I'd move them to JNI_OnLoad
to have all the fields initialisation in one place and reduce complexity here a bit. It would be good to know performance implications of this, I'm just assuming they are negligible
thanks Richard |
Description of changes:
JNI class/fieldID lookup can be an expensive operation. This PR moves out the class/fieldId lookup outside the next call to minimise the overhead.
More information:
https://developer.android.com/training/articles/perf-jni#jclass,-jmethodid,-and-jfieldid
https://developer.ibm.com/articles/j-jni/#notc
http://normanmaurer.me/blog/2014/01/07/JNI-Performance-Welcome-to-the-dark-side/
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.