Skip to content

Conversation

@richarddd
Copy link
Contributor

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.

@andclt andclt requested review from carlzogh and smirnoal August 10, 2022 09:03
@msailes
Copy link
Contributor

msailes commented Aug 10, 2022

@smirnoal can you take a look at this?


if(response.xray_trace_id != ""){
CHECK_EXCEPTION(env, xrayTraceIdField = env->GetFieldID(invocationRequestClass , "xrayTraceId", "Ljava/lang/String;"));
if(xrayTraceIdField == nullptr){
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

@smirnoal
Copy link
Contributor

thanks Richard

@smirnoal smirnoal merged commit 6a3ffd5 into aws:master Aug 18, 2022
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.

4 participants