-
Notifications
You must be signed in to change notification settings - Fork 2
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
MethodHandles vs Reflection invocation #1
Comments
Point 3 - Building middleware and installing it with maven did the trick for me. I had to refresh some weird Maven Cache in my IDEA project before it accepted it. |
Point 2 - Thank you for this hint. It will take a long time till we run into serious performance issues where these tricks are required. KISS. |
Point 1 - Didn't think about it - may be a good idea if I can managed to pass a "context" object around into the lambda. |
a lambda api is helpful syntactical sugar allowing a complete operator to be defined and registered in as little as 1 or 2 lines of java. an ordinary synchronously executed operator should involve just one abstract method that takes the arguments terms and returns some feedback term or task. an asynchronous operator can wrap the same simple lambda api the "termizer" is as simple as it could be, with or without caching: a bidirectional term -> object, object -> term mapping https://github.com/automenta/narchy/blob/volatile1/nal/src/main/java/nars/concept/Operator.java#L103 opjects, along with the execution decider, manages the end-to-end work of a multithreaded asynchronous atomically-debounced execution/feedback system triggered by goal truth and scheduled according to occurrence time. not sure how much simpler this could be designed |
A generic method invocation implementation for operators is a good idea. Here are a few suggestions to expand this
a convenient API for implementing operators with a lambda, allowing registry of operator with at minimum a name string and a lambda that receives argument terms. from this, multiple arity subclasses with implicit arity checks can be defined like https://github.com/automenta/narchy/blob/volatile1/nal/src/main/java/nars/term/Functor.java#L197
java MethodHandles api can be used to get better performance than the reflection api (Method.invoke). It is like the lower level way of constructing a method call and the stack that supplies the arguments. Caching a MethodHandle to a function when calling with specifi argument types, once resolved to a specific parameter type list, should be faster than the equivalent Method.invoke. https://github.com/automenta/narchy/blob/volatile1/app/src/main/java/nars/op/java/Opjects.java#L162 here i construct dynamic MethodHandles to dynamically specified methods. also there is a specific protocol for for converting arbitrary POJO's to and from Term's https://github.com/automenta/narchy/blob/volatile1/app/src/main/java/nars/op/java/DefaultTermizer.java#L31 .. MethodHandles should get nearly if not just as fast as if you generated custom accessor classes via bytecode because this is what the JIT will do with them anyway
there is a dependency issue with opennars-applications unable to resolve opennars-middleware from maven. thats what led me here. but i can just copy the two classes it needs to get it running
The text was updated successfully, but these errors were encountered: