News for hackers. Stuff that matters.
Re:Quick Tips for Fast Code on the JVM by twic on Sunday December 31, 2017 @02:02PM (#16042071)
Careful, though. It costs about a millisecond to do a return trip across the JNI boundary, so don't do that anywhere near an inner loop. Accessing Java objects from native code is also a pain, with potential performance gotchas (pinning, mostly).

An approach I've seen work is to have dedicated Java and native threads, communicating via shared memory. We have some funky in-house code for this, but I think Aeron [1] should be a good open source option.

[1] https://github.com/real-logic/aeron

Re:Quick Tips for Fast Code on the JVM by badlogic on Sunday December 31, 2017 @11:31PM (#16044714)
JNI roundtrips definitely do not cost 1ms per trip.
Re:Quick Tips for Fast Code on the JVM by twic on Tuesday January 02, 2018 @11:16AM (#16052735)
True. I did some benchmarking a while ago, and had that number in my head. Revisiting it now, it seems to be way off - more like 5 nanoseconds with -Xcheck:jni on. Code:

https://github.com/tomwhoiscontrary/jni-bench

Re:Quick Tips for Fast Code on the JVM by kodablah on Sunday December 31, 2017 @05:30PM (#16043381)
True of course. I just feel like many people had long since taken native off the table because of the burdens of cross platform c/c++ development. But I found Rust+JNI so easy that I think it should be a reasonable tool in every JVM optimization toolbox.
Re:Quick Tips for Fast Code on the JVM by raz32dust on Monday January 01, 2018 @06:19AM (#16045673)
"It costs about a millisecond to do a return trip across the JNI boundary" - Do you have a source on this? Seems unlikely since most system calls would be way too slow if this were true?
Re:Quick Tips for Fast Code on the JVM by wging on Sunday December 31, 2017 @03:21PM (#16042667)
> Accessing Java objects from native code is also a pain, with potential performance gotchas (pinning, mostly).

What do you mean by pinning? If you mean pinning threads to cores, how does that relate to JNI?

Re:Quick Tips for Fast Code on the JVM by bennofs on Sunday December 31, 2017 @04:54PM (#16043212)
Probably pinning the object in memory, so that you can keep a stable reference to it without the danger of the GC moving it away under your pointer.
Re:Quick Tips for Fast Code on the JVM by lamansion on Sunday December 31, 2017 @06:43PM (#16043687)
Do some research on GC locker.