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

Clean up, optimize and uniform code #22

Open
DanieleDiBenedetto opened this issue May 21, 2020 · 1 comment
Open

Clean up, optimize and uniform code #22

DanieleDiBenedetto opened this issue May 21, 2020 · 1 comment

Comments

@DanieleDiBenedetto
Copy link
Collaborator

DanieleDiBenedetto commented May 21, 2020

We should refactor the JNI code in api/src/lib to make it cleaner:

  • Remove all code duplications (e.g. when creating a jobjects to return, when evaluating a Result and return j_object::null if it is an Err variant, and so on);
  • Remove all unnecessary input parameters (like the JClass when they are not needed);
  • Remove unnecessary copies and write-to-fixed-size-buffer operations;
  • Java classes and methods can be cached at startup (e.g. by implementing JNI_onLoad() function and putting the code inside it), so that it won't be necessary to perform a lookup each time they are needed (like in https://github.com/exonum/exonum-java-binding/tree/master/exonum-java-binding/core/rust);
  • Use a logger (we could initialize it using the same JNI_onLoad() function) and log all the operations (be sure that doesn't conflict with the one employed by the SidechainsSDK)
  • Uniform the logic to perform certain operations (e.g. the "free" functions are sometimes implemented by taking as argument the pointer to free, other times by directly working with the JObject containing the pointer);
  • Refactor the code in api/ginger_calls.rs and api/lib.rs by splitting it in submodules;
@DanieleDiBenedetto DanieleDiBenedetto changed the title Clean up and uniform JNI code Clean up, optimize and uniform JNI code Aug 6, 2020
@DanieleDiBenedetto DanieleDiBenedetto changed the title Clean up, optimize and uniform JNI code Clean up, optimize and uniform code Nov 5, 2020
@DanieleDiBenedetto
Copy link
Collaborator Author

For what regards:

Java classes and methods can be cached at startup (e.g. by implementing JNI_onLoad() function and putting the code inside it), so that it won't be necessary to perform a lookup each time they are needed (like in https://github.com/exonum/exonum-java-binding/tree/master/exonum-java-binding/core/rust);

I benched it locally and it seems to not lead to any significant benefit, so let's give to this point a low priority.

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 a pull request may close this issue.

1 participant