MCPcopy Index your code
hub / github.com/evolvedbinary/jni-benchmarks

github.com/evolvedbinary/jni-benchmarks @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
553 symbols 1,110 edges 86 files 105 documented · 19%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

JNI Benchmarks

Build Status License

We provide the code for a small set of benchmarks to compare various approaches to solving common JNI use-cases and then present the results.

The benchmarks at present are:

  1. com.evolvedbinary.jnibench.common.call - Benchmarks for Creating Objects with JNI (results).

  2. com.evolvedbinary.jnibench.common.array - Benchmarks for Passing Arrays with JNI (results).

  3. com.evolvedbinary.jnibench.common.bytearray, and com.evolvedbinary.jnibench.common.getputjni - Benchmarks for JNI Data Transfer.

Reproducing

If you want to run the code yourself, you need to have Java 8, Maven 3, and a C++ compiler that supports the C++ 11 standard. You can then simply run:

$ mvn clean compile package

In the target/ sub-directory, you will then find both a jni-benchmarks-1.0.1-SNAPSHOT-application folder and a jni-benchmarks-1.0.1-SNAPSHOT-application.zip file, you can use either of these. They both contain bash scripts in their bin/ sub-folders for Mac, Linux, Unix and batch scripts for Windows. These scripts will run a single iteration of the benchmark.

If you want to run multiple iterations and get a CSV file of the results, you can use benchmark-100.sh and/or benchmark-100-with-close.sh, or array-benchmark-100.sh.

JMH support

We have support for running the tests via JMH, see jmh-benchmarks.sh. You can also pass --help to the script to see JMH options.

Byte array benchmarks

There are two benchmarks, which are currently available only via JMH: ByteArrayFromNativeBenchmark and ByteArrayToNativeBenchmark. They can be run multiple times using jmh-benchmarks-parametrized.sh with:

./jmh-benchmarks-parametrized.sh -i 10 -b ByteArrayToNativeBenchmark -o results/ -f csv

The above command will run JMH with ByteArrayToNativeBenchmark benchmarks 10 times and store result in CSV files in results directory. You can also pass --help to the script to see additional JMH options that can be used.

Results can then be plotted using the process_byte_array_benchmarks_results.py script. For example, to produce results for the ByteArrayToNativeBenchmark benchmarks, you can run:

python3 process_byte_array_benchmarks_results.py -p results/ --param-name "Param: keySize" --chart-title "Performance comparison of passing byte array with {} bytes via JNI"

Command line parameter p expects a path to the directory with the JMH result CSV files from running the benchmarks with jmh-benchmarks-parametrized.sh. The {} in the chart-title parameter will be replaced by the value from the param-name column.

Other Resources

  1. Java Foreign Interface prototype and performance results in RocksJava (i.e. Panama) - https://rocksdb.org/blog/2024/02/20/foreign-function-interface.html
  2. RocksJava API Performance Improvements - https://rocksdb.org/blog/2023/11/06/java-jni-benchmarks.html

Extension points exported contracts — how you extend this code

JniListSupplier (Interface)
(no doc) [8 implementers]
src/main/java/com/evolvedbinary/jnibench/common/array/JniListSupplier.java
BenchmarkInterface (Interface)
(no doc) [4 implementers]
src/main/java/com/evolvedbinary/jnibench/consbench/BenchmarkInterface.java
BenchmarkFixture (Interface)
(no doc) [4 implementers]
src/main/java/com/evolvedbinary/jnibench/consbench/BenchmarkFixture.java
AllocationCache (Interface)
(no doc) [1 implementers]
src/main/java/com/evolvedbinary/jnibench/jmhbench/cache/AllocationCache.java

Core symbols most depended-on inside this repo

size
called by 35
src/main/java/com/evolvedbinary/jnibench/common/array/AllocateInCppGet2DArrayListWrapper.java
release
called by 31
src/main/java/com/evolvedbinary/jnibench/jmhbench/cache/AllocationCache.java
acquire
called by 25
src/main/java/com/evolvedbinary/jnibench/jmhbench/cache/AllocationCache.java
get
called by 25
src/main/java/com/evolvedbinary/jnibench/common/bytearray/GetByteArray.java
equals
called by 21
src/main/java/com/evolvedbinary/jnibench/common/array/FooObject.java
GetKey
called by 18
src/main/c++/getputjni/GetPutJNI.cpp
checksumBuffer
called by 13
src/main/java/com/evolvedbinary/jnibench/jmhbench/cache/AllocationCache.java
get_nativeHandle
called by 12
src/main/java/com/evolvedbinary/jnibench/common/NativeBackedObject.java

Shape

Method 341
Function 111
Class 95
Interface 4
Enum 2

Languages

Java72%
C++21%
Python7%

Modules by API surface

src/main/java/com/evolvedbinary/jnibench/common/array/AllocateInCppGet2DArrayListWrapper.java29 symbols
jmhplot.py25 symbols
src/main/c++/getputjni/GetPutJNI.cpp21 symbols
src/main/c++/bytearray/GetByteArray.cpp20 symbols
src/main/java/com/evolvedbinary/jnibench/jmhbench/PutJNIBenchmark.java19 symbols
src/main/java/com/evolvedbinary/jnibench/jmhbench/GetJNIBenchmark.java19 symbols
src/main/c++/array/Portal.h19 symbols
src/main/java/com/evolvedbinary/jnibench/common/getputjni/GetPutJNI.java18 symbols
src/main/java/com/evolvedbinary/jnibench/jmhbench/ByteArrayFromNativeBenchmark.java16 symbols
jmhrun.py16 symbols
src/main/java/com/evolvedbinary/jnibench/jmhbench/cache/LinkedListAllocationCache.java14 symbols
src/main/java/com/evolvedbinary/jnibench/jmhbench/cache/NettyByteBufCache.java12 symbols

For agents

$ claude mcp add jni-benchmarks \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact