Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Examples of high JNI performance overhead?  (Read 6200 times)
0 Members and 1 Guest are viewing this topic.
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Posted 2006-08-18 23:13:41 »

Hello,

We have folks working on reducing JNI overhead, so they need something
to test their work on, so we're looking for benchmarks (or better yet, real
applications) which could show high JNI overhead.

It would be especially useful if you could quantitize the amount
of overhead by some measurements.

We in 2D typically do this by rendering some tiny primitives which
don't take any measurable time at all by themselves, so that most
of what's the time is spent on is overhead.  This is for native method
calling.
 
Other example is pulling data from java objects.

We have a couple of micro-benchmarks (internal and one external),
but it would be useful to have some real-world applications.

Typical Swing applications have too much stuff going on on java level,
so the JNI overhead (for rendering calls, for example), is almost
non-noticeable. Games, on the other hand, may be more
prone to the overhead.

Thanks,
  Dmitri
Java2D Team
Offline princec

JGO Kernel


Medals: 366
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2006-08-20 19:11:20 »

Because of the way we use the APIs, JNI overhead is just totally lost in the noise. Might not really be worth it for you to optimise this too much more.

Cas Smiley

Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #2 - Posted 2006-08-21 00:01:37 »

I remember a few months ago when me and Riven were doing a SIMD library, we benchmarked the JNI overhead to be 1100ns on 6.0 (that was an empty method).

Generally, if things are in ns time, i just ignore them. Theres always something taking more time...

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #3 - Posted 2006-08-21 09:40:52 »

Maybe jake2 would be a good candidate? IIRC, quake2 is quite old-school in the way it uses OpenGL, so I expect lots of OpenGL calls through JNI. Not sure though, maybe the jake2 author can confirm.

Offline princec

JGO Kernel


Medals: 366
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2006-08-21 11:16:06 »

Yeah, but it would be optimising really badly written code, if you see what I mean. Sorta pointless. The OpenGL API is designed to work fast even with big overheads if you simply use it right in the first place.

Cas Smiley

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2006-08-21 12:21:52 »

I see your point, but quake2 isn't necessarily badly written. It's just old legacy code from the days where you didn't have much of a choice than to write it like that in OpenGL. As a benchmark, it could still be usable as a 'real world' application, even if it's old.

That said, I'd probably just create some microbenchmarks, and getting data from java objects through JNI is probably much more in need of some optimization. If you want to access java for some AFFT (Amazingly Fast Fourier Transform) from your C program, for example  Wink Grin

Offline rreyelts

Junior Member




There is nothing Nu under the sun


« Reply #6 - Posted 2006-08-21 14:44:37 »

In general, when I'm looking for speed involving JNI, I cross the Java/native boundary using DirectByteBuffers. When i'm looking for convenience, I just use Jace to proxy my objects back and forth. If I had any advice for speeding up JNI access, it would be to sort out all the performance issues regarding usage of Buffers.

1) Fix the problems with polymorphism. I seem to remember that there were significant performance issues once you use more than one type of Buffer. The advice was something along the lines of "only use 1 Buffer type in your app", and "cast to MappedByteBuffer". In any case, it needs to be fixed.

2) Fix bound checks or w/e it is that slows down Buffer accesses. This board has several little benchmarks laying around the site which show that people can get significant speedups using sun.misc.Unsafe in comparison to going through the Buffer interface.

3) Fix access to heterogenous data. Rather than having some homogeneous array of bytes, floats, or ints, my data is usually structural in nature. For example,

struct {
  byte b1;
  byte b2;
  int i1;
  int i2;
  float f1;
  float f2;
  byte[] bytes;
}

This doesn't lend itself well to optimized access, because you typically end up using ByteBuffer, which doesn't perform as well as simple mem accesses should.

About me: http://jroller.com/page/rreyelts
Jace - Easier JNI: http://jace.reyelts.com/jace
Retroweaver - Compile on JDK1.5, and deploy on 1.4: http://retroweaver.sf.net.
Offline Niwak

Senior Member


Medals: 1
Projects: 1



« Reply #7 - Posted 2006-08-22 17:36:47 »

I fully agree with the previous post.

I will just add a note on this point ;
2) Fix bound checks or w/e it is that slows down Buffer accesses. This board has several little benchmarks laying around the site which show that people can get significant speedups using sun.misc.Unsafe in comparison to going through the Buffer interface.

For me there has allways been a strange design in Java library which exception handling ; external error and internal error are alltreated as exceptions. From my point of view external errors are exceptions (IO, database, ...), internal errors should stay at the development level and hence are assertions. 'assert' has been introduce since java 1.4. but does not seems to be used extensively in the core library. I think this could be very usefull especially for time critical section like NIO buffer accesses.

   Vincent
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #8 - Posted 2006-08-23 17:55:38 »

3) Fix access to heterogenous data. Rather than having some homogeneous array of bytes, floats, or ints, my data is usually structural in nature.

<cas>Structs! Structs! Structs!</cas>

Quote
For me there has allways been a strange design in Java library which exception handling ; external error and internal error are alltreated as exceptions. From my point of view external errors are exceptions (IO, database, ...), internal errors should stay at the development level and hence are assertions. 'assert' has been introduce since java 1.4. but does not seems to be used extensively in the core library. I think this could be very usefull especially for time critical section like NIO buffer accesses.

Perhaps, but you'll never be able to fully elimenate bounds checks for fear of all manner of buffer overrun attacks and undefined behaviour.
Offline princec

JGO Kernel


Medals: 366
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2006-08-29 12:50:30 »

I didn't want to bang on about structs (well, "mapped data"), but yeah, that's what he's talking about there Smiley

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #10 - Posted 2006-09-03 09:12:32 »

I guess the fact that JNI was quite slow for a tight C/Java coupling is the reason why no JNI limited real world programs exist.
Almost everybody who uses JNI knows about its performance impact, so everybody starts his/her design  with this limitations in mind.

lg Clemens

Btw. great that someone is working on this :-)
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #11 - Posted 2006-09-03 17:26:57 »

does any of this have to do with "blackbird" ? http://www.java-gaming.org/forums/index.php?topic=6939.0

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline CommanderKeith
« Reply #12 - Posted 2006-09-12 04:07:40 »

does any of this have to do with "blackbird" ? http://www.java-gaming.org/forums/index.php?topic=6939.0

I think its just optimizing, I happened upon this today: http://blogs.sun.com/fatcatair/entry/micro_benchmarks_just_say_no.

Apparently Steve Goldman has found a way to reduce JNI overhead by 15%.

Keith

Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #13 - Posted 2006-09-15 05:57:28 »

Yep, Steve and others in hs team are looking into improving
jni performance. We (Java2D) have been whining about it
for a long time, so they finally have some time they can spend on this..

Dmitri
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #14 - Posted 2006-09-26 08:00:36 »

looks like a case where JNI overhead is significant:
http://forums.java.net/jive/thread.jspa?threadID=18620&tstart=0
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #15 - Posted 2006-09-26 15:13:13 »

All of the floating point to integer conversions and vice versa are intrinsified by the Java HotSpot VM's compilers, so that native code and any associated overhead is not used.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #16 - Posted 2006-10-01 10:20:28 »

As I'm using direct ByteBuffers for my networking app, I'm wondering if their "put" method is intrinsified? If not, why not?

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #17 - Posted 2006-10-01 18:11:50 »

As far as I remember I've heard its intrinsified.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (35 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!