Opt-in for trivial native method calls
Samuel Audet
samuel.audet at gmail.com
Thu Jun 2 11:49:07 UTC 2022
Hi,
6ns is already pretty close to what you'd get for a function call in
C/C++, without any Java involved. It sounds like what you're looking for
is function inlining, which is actually a very common use case, and
personally the only thing that I care about because if we can inline
functions, we can implement all the features that this project is
working on, but as libraries instead of as part of the core API.
Unfortunately, function inlining is out of scope for Panama.
You may want to check out this project for that though:
https://github.com/alibaba/fastffi
Samuel
On 6/2/22 19:14, Felix Cravic wrote:
> Hello, coming here after a recommendation from reddit [0] I want to pitch my wish for the Linker API to support "trival" native function.
> My benchmark showed an average latency of around 6ns when calling a native method, which is more than fine most of the time, but fall short for inexpensive calls.
>
> To give a relevant example that could take advantage of such feature, my current toy project [1] involve making the JVM version of Unity's burst compiler [2] which consist in JIT compiling JVM bytecode using LLVM with the hope of getting better performance for highly specialized code (custom intrinsics, stack allocation, value class without valhalla, other fanciness...). And while the calling latency does not make it impossible, it does make it inefficient for taking advantage of specialized instructions (that may not be available in the JDK api) and relatively small methods that could still outperform hotspot equivalent.
>
> I definitely agree that my situation is not the most common (I am responsible for all the native methods, generate class dynamically to create the static method handles) but giving access to low-level tweaks seem like a great solution to me. I am also not sure of what are the tradeoffs of these trivial methods (is it only a matter of safepoint?) so I would be happy to get more technical details.
>
> Thanks!
>
> [0] - https://www.reddit.com/r/java/comments/v33d44/panama_foreign_function_overhead_how_can_it_be/
> [1] - https://github.com/TheMode/Spe
> [2] - https://docs.unity3d.com/Packages/com.unity.burst@0.2-preview.20/manual/index.html
>
More information about the panama-dev
mailing list