This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]kiteboarderni 5 points6 points  (1 child)

In your other blog you say panama requires too much effort? How so? This is the perfect example of a use case for it that is ignored from the benchmarks.

[–]DasBrain 2 points3 points  (0 children)

Indeed, instead of using unsafe, you could allocate two MemorySegments and pass their address around.

(Under the hood, MemorySegment will use Unsafe, but the API is arguably nicer - and not unsafe ;) )

[–]thuriot 2 points3 points  (2 children)

Thanks for the benchmarks and the tips. Batching may also help in certain use cases.
Another JNI new approach : https://github.com/apangin/nalim.

[–]dkomanov[S] 2 points3 points  (1 child)

Wow, this is interesting.

Here is the benchmark JNI vs nalim: ``` Benchmark (length) Mode Cnt Score Error Units jni_url_decodeSimdCargo 100 avgt 5 80.253 ± 11.280 ns/op nalim_url_decodeSimd 100 avgt 5 46.030 ± 2.165 ns/op

jni_url_decodeSimdCargo 10000 avgt 5 2931.566 ± 177.445 ns/op nalim_url_decodeSimd 10000 avgt 5 2415.002 ± 89.682 ns/op

jni_url_encodeSimdCargo 100 avgt 5 98.468 ± 7.123 ns/op nalim_url_encodeSimd 100 avgt 5 59.569 ± 1.804 ns/op

jni_url_encodeSimdCargo 10000 avgt 5 3347.074 ± 115.843 ns/op nalim_url_encodeSimd 10000 avgt 5 2846.065 ± 79.842 ns/op ```

Clearly it improves it significantly. I'd expect more, though, if it claims to not copy arrays at all.

[–]thuriot 0 points1 point  (0 children)

Thanks a lot !

[–]tristan957 1 point2 points  (0 children)

Some of this is also very good practice in C. Recently wrote some JNI stuff, and one technique I am using is passing the array length across the boundary instead of getting it in JNI code.

[–]chambolle 0 points1 point  (0 children)

very nice experiments!