Skip to main content
gamedev.net
🔒 Locked

java performance

Started by imbro May 1, 2004 at 12:18 AM 8 replies 1.2k views
Original Post
imbro
imbro
Hello, I've been a gamedev.net forum reader for years, but never registered or posted a message until today. I don't know what changed about today. Oh well. I've seen a lot of questions/comments about whether Java is suitable for creating commercial games. I wanted to make a comment about that. We have written a commercial quality action orientated 3d game in Java (about 100,000 lines of code). The underlying proprietary game engine is in c++, but all the game code is in Java (using JNI to implement the engine interface). It was an interesting excersize, and this is what I learned: 1) They're was no material performance penalty for writing the game code in Java. I know this because we happened to have c++ and java versions of the same game side by side, and saw no real difference (maybe 1-5% slower for Java). This was with the latest version of Java and HotSpot. We also used the 'Jet' Java optimizing compiler, but didn't see any real improvement in FPS with Jet over just using hotspot, but it did allow us to have a distributable that didn't require the Java runtime. 2) Be careful with GC. Creating lots of small objects per frame like vectors, matrices and strings will cause noticable GC hits to the game, no matter how you tweak the gc methods or parameters. Fortunately, it turns out that it's pretty easy to avoid GC'ing at all. (if someone's interested i can explain how) 3) Coding is noticibly speedier in Java than in c++. I attribute the speed up to: a) having one source file per class (as opposed to maintaining a .h and .cpp for c++). b) The Idea IDE by IntelliJ (which we used for development) because of: 1) Autocompletion/function parameter prompting that actually works ALL THE TIME. (Visual C++ people know what I'm talking about) 2) Massive/Insane refactoring capability like I have never seen before in my life. I develop iteratively, constantly shuffling around classes, renaming, creating new classes, relocating variables, rearanging class hierarchies etc. The refactoring capability in the Idea IDE did it all automatically. Stunning. (I know all this is the IDE, not Java, but my belief is Java makes this possible. Its much harder for an IDE to do this with c++) Finally The Java version of our game worked fine, but we ended up not using the Java version because of a number of reasons: 1) We became an authorized XBox developer, and so had to consider porting to the XBox. 2) The Java language tends to be a bit too simplistic for my tastes. I like enums, multiple inheritance, default parameters, templates, preprocessor directives etc. (an aside: multiple inheritence with virtual base classes is one of the most wonderful things to facilitate code reuse I've ever seen.) 3) Maintaining the engine interface through the JNI got to be a pain. Nothing wrong with JNI (in fact it performed a LOT faster than I expected), it was just because it was yet another layer. Anyways, this wasn't to promote Java or anything. In fact I've been an asm,c,c++ programmer for the past 30 years (over 1.5 mil lines of code written). But I did enjoy writing in Java and wanted to share my experience. My appologies if this is a tired topic. Thanks [edited by - imbro on May 1, 2004 11:55:51 AM]
lancekt
lancekt
Interesting comments. A few thoughts in response...

quote:

1) They're was no material performance penalty for writing the game code in Java...


Well, you know what they say about 90% of execution time being spent in 10% of the code. If you used a C++-based engine then all of that performance-critical 10% would be in C++, no?

Doesn't sound all that different from the way many games use scripting languages for their game logic.

quote:

a) having one source file per class (as opposed to maintaining a .h and .cpp for c++).


I've personally found Java source files with interface and implementation crammed into the same space outrageously difficult to read and maintain, but maybe that's just me.

quote:

(an aside: multiple inheritence with virtual base classes is one of the most wonderful things to facilitate code reuse I've ever seen.)


Isn't this essentially the same thing as using interfaces in Java?

[edited by - lancekt on May 1, 2004 1:28:59 AM]
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
imbro
imbro
quote:

Well, you know what they say about 90% of execution time being spent in 10% of the code. If you used a C++-based engine then all of that performance-critical 10% would be in C++, no?

Doesn''t sound all that different from the way many games use scripting languages for their game logic.



I agree. And I wanted to state up front that the engine was in c++. I''m not sure when people say they''re concerned Java is too slow if they mean for just coding the game or for coding the game and the engine. As far as the game goes, its very possible we could have just used lua or something and it still would have been fine.

quote:

Isn''t this essentially the same thing as using interfaces in Java?



Unless I totally missed the boat on Java Interfaces, I don''t see it as the same. You can get there with interfaces, but its much less effort with MI. (and cleaner, IMHO)
lancekt
lancekt
quote:

Unless I totally missed the boat on Java Interfaces, I don''t see it as the same. You can get there with interfaces, but its much less effort with MI. (and cleaner, IMHO)


Ah, right. I think I misunderstood what you were describing. (The point being that you can actually put code in C++ abstract base classes but not in Java interfaces, right?)
Orin Tresnjak | Graphics ProgrammerBethesda Game StudiosStandard Disclaimer: My posts represent my opinions and not those of Bethesda/Zenimax, etc.
imbro
imbro
Correct. And they don''t necessarily have to be abstract (and usually aren''t in my case)
Aldacron
Aldacron
And the thing is, with tools out there now such as LWJGL and JOGL, you can still get excellent performance by doing the engine in Java as well. The performance myth is a dead horse, but there are many, many people standing around with a stick and nothing better to do. The real hurdle with Java right now is distribution and availability. For a commercial shop packaging a CD and targeting the PC only, it''s non-issue. But for everyone else it can be a show stopper - as in your case with the XBox deal.
daveangel
daveangel
I''ve programmed in all the languages you mentioned and thanks for reminding me why I like java the best:
2) The Java language tends to be a bit too simplistic for my tastes. I like enums, multiple inheritance, default parameters, templates, preprocessor directives etc.
Who was it that said that if you write clever code you''ll never be able to debug it since it''s twice as hard as writing the code in the first place!

If God played dice, He''d win.
—Ian Stewart, Does God Play Dice? The Mathematics of Chaos
If God played dice, He'd win.—Ian Stewart, Does God Play Dice? The Mathematics of Chaos
Zahlman
Zahlman
Brian Kernighan, IIRC. It''s floating around in some sigs here.

quote:

(I know all this is the IDE, not Java, but my belief is Java makes this possible. Its much harder for an IDE to do this with c++)


true!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.