Archived

This topic is now archived and is closed to further replies.

Sieggy

[java] Feelings on Java3D?

Recommended Posts

I''ve been looking at options for doing iso engines in Java. I''ve come across references to Java3D and looked up some info on it and wanted to get some thoughts on it. While the game world still seems heavily entrenched in C/C++ the business world is rapidly moving to Java so it would be nice that my hobby (game programming) corresponds to my day job (business programming). So thoughts any thoughts on its merits, or lack thereof would be appreciated. Thanks! Sieggy

Share this post


Link to post
Share on other sites
Sieggy,

I''ve been going through a similar process. I have found that with working in Java all day and going home to work on C++ after a few hours spending time with the family is just not working that well.

Although the languages are very similar, it still takes some time to get back into the C++ groove. And if you go a few day''s without touching it, it takes much longer to get back into it.

So, I have moved over to Java for my current game development efforts. For me it makes a great deal of sense since writing games in Java only improves my Java skills for my day job, and using Java in my day job only improves my Java skills for my game development.

Now as far as Java3D goes, I think it still has a way to go before it can even compete with Direct3D and OpenGL. But the JDK1.4 does look promising. And since it is still in Beta, we can only hope for a bigger performance boost in the final release.

At the JavaOne conference, I saw the new JDK1.4/Java3D in action. I''m not sure what hardware it was running on (my guess is it was a Sun workstation), and the performance was much better than before (16fps versus .8 fps for the same demo).

So, for now I''m going to stick with the Java stuff and see what I can make it do.

borngamer

Share this post


Link to post
Share on other sites
Where did you see the JDK1.4/Java3D demo? I talked to the Java3D people and they said they haven''t even tried 1.4 with Java3D.

The Grand Canyon demo I saw was with 1.4 and GL4Java.

[<><]

Share this post


Link to post
Share on other sites
Hi!

I have had the same thoughts as both Sieggy and borngamer. Why retreat to C++ for games, when Java is working well for other task?

I have tested Java 3D a little bit. To learn Java 3D, I bought the book "Ready-to-Run Java 3D" by Kirk Brown & Daniel Petersen. I have gone through the book and run all the examples in the book. The examples where all to simple to get a real impression about the performance. However, with very simple code the visual appearance was quite impressive.

One thing that annoyed me was that exclusive full-screen mode was not available. Today, when looking at JDK 1.4, I was pleased to see that this screen-mode was available. But I didn´t get if it was possible to run Java 3D in full-screen mode. But I think that full-screen exclusive mode is a great way to improve the graphic performance of Java.








Johan Karlsson

Share this post


Link to post
Share on other sites
If you hadn't noticed already, there's a tutorial available at
[html]http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html[/html]
on the exclusive mode in 1.4

Haven't tried it yet though.

oh yeah and on the Grand Canyon demo at JavaOne:
[html]http://java.sun.com/products/jfc/tsc/articles/jcanyon/[/html]

Edited by - PeterB on July 10, 2001 9:54:37 AM

Share this post


Link to post
Share on other sites
Java and Java3D seems like a good way to build a game if you don't care about speed. I'm building a 3D editor + engine in c++/directx so I need all the speed I can get. It's true that Java is 20x slower than c++. I wrote vector of 40,000 chars to a file in Java in 10,000 iterations. Open file, write chars, close file, rinse wash repeat

Results:
a)Java - 50 seconds
b)C++ STL (ofstream) - 30 seconds
c)C (FILE) - 9 seconds
d)win32 api - 1.6 seconds.

Binary output and done on win98 with 1ghz 266 tbird on FIC AD11 DDR mobo, 2100ddr ram 128mb and ibm60 gxp ata100 harddrive.

As you can see if you have large worlds to write to disk then it will be slowest in Java. Also I don't think you can protect your Java files from privy eyes or is there a way I don't know about? I can open .class files with text editor and peek inside. I'm a Java newbie

Edited by - JD on July 11, 2001 1:13:51 AM

Share this post


Link to post
Share on other sites
Hi!

I have a couple of things that I want to point out regarding the performance of Java.

First of all a comment on JD''s "benchmark"; It''s not enough to measure one thing (writing to file) and then say that Java is slow. Back in ´97 I wrote my Master Thesis on the subject of Java vs C++ performance. This was when JIT just arrived at the market and there was one adoptive JIT compiler available. No Hotspot and so on. I did a series of microbenchmarks, like comparing for-loops and array access etc. In the case of a for-loop there wasn´t any big differences, but in the case of array access there was huge differences.

However, it´s the overall performance thats counts in real-life applications. Different types of applications, have different types of characteristics. Thus, Java is more suitable in some areas than others. For example, Java is fast on number crunching. A nice real-world example is the Colt library:
http://tilde-hoschek.home.cern.ch/~hoschek/colt/index.htm

The promising thing about Java3D is the possibility to use a hardware accelarator, which most graphic cards have today. One problem today is that many graphic cards have only 3D accelaration when using fullscreen mode. However, the 1.4 release seems to have solved that problem. I think that using Java 3D in fullscreen mode with a hardware accelarator could be rather fast.

Regards
Johan

Share this post


Link to post
Share on other sites
Hi!

One more thing. It´s possible to protect your .class file by using an obfuscator. Many time a tool like this i combined with an optimizer. A good example of this is Jopt://www-i2.informatik.rwth-aachen.de/~markusj/jopt/

Some obfuscator could ruin the code and make it impossible to execute. However, I have tested Jopt on our products and have not noticed any trouble running them. The become smaller, faster and more difficult to read.

Regards
Johan

Share this post


Link to post
Share on other sites
JavaJohan, thank you for the link. That piece of code is interesting. For someone using the obfuscator a backup of data would be helpful before running it on the real files.

I hear slow loading times of games all the time from frustrated gamers. Compare file saving of win32 2 seconds versus 50 seconds for Java. It''s better to do benchmarks now and avoid headaches then find yourself with nice unplayable game later when tons of code was already written. Profile, profile and then do some more profiling. For C++ users, Amd has pretty decent free profiler on their site. It tells you what functions are taking the longest to process, etc.

Java3D + Java is slow (interpretative languages usually are) but it trades that for the flexibility which I think is very valid for non-time critical applications. Every tool has it''s place. I really like the write code once run anywhere paradigm, that''s why I''m eyeing Java now. If my game has enough speed under java then I''ll use Java, if not I''ll use c++ and os api. Will check out Java3D in near future, maybe I don''t need to talk to hardware on lowest of levels, just need poly handling api and I''ll write my own scene graph, portals like I''m doing now.

Share this post


Link to post
Share on other sites
JD,

You could not be furter off base with your speed comments. Most poeple don''t relize that even IO under java can be as fast as C. The problem is that most people''s first attempt to profile java''s IO speed are equivilent to using getch() and putch() in C. Once they have learned the API and take advantage of buffered IO methods and API the speed are alost identical.

"Java3D + Java is slow" Have you actually seen any of the stuff comming out. Even with major performance bottlenecks in the Java3d scene graph tech people are turning out some amazing work that will only continue to get faster as the technology matures. I''ll admit it seems like there is a little voo-doo going on here, but these people seem to be getting incredible nummbers because they have been working within the tech for a while now.

Java is as slow as all interpreted languages. Java is a bytecode language that often runs nativle thanks to the efforts of JIT compilers and agressive array inlining the speeds are only getting better.

There are still some areas of java that are slow. Swing is, but that has the most to do with off-screen-buffering this is being looked into being fixed at the JVM level so that the performace hit will go away there.

Please, check your numbers before bashing java. Experienced java programmers can ususally get performace that is very close to the "native" brotherin with the right tuning.

Share this post


Link to post
Share on other sites
JD:

maybe you should check out this sample chapter from the "Java platform performance" book

i/o
http://developer.java.sun.com/developer/Books/performance/ch04.pdf

and you might as well take at look at the other articles there too:

swing
http://developer.java.sun.com/developer/Books/performance/ch10.pdf

garbage collection
http://developer.java.sun.com/developer/Books/performance/performance2/appendixa.pdf

btw:
a)Java - 50 seconds
b)C++ STL (ofstream) - 30 seconds

you are aware that chars in Java are actually 2 bytes are you?

Edited by - kvh on July 11, 2001 6:37:44 PM

Share this post


Link to post
Share on other sites
Here''s the code, can you speed it up? I''m interested.

  
import java.util.*;
import java.io.*;

public class test extends java.lang.Object
{
public test() { }

public static void main (String args[]) throws IOException
{
final int CHARS_TO_WRITE = 40000;
final int NUMBER_OF_ITERATIONS = 10000;

char[] chars = new char[CHARS_TO_WRITE];

for(int i = 0; i < CHARS_TO_WRITE; ++i)
chars[i] = ''c'';

long base, time;

// Start timing the code

base = System.currentTimeMillis();

for(int j = 0; j < NUMBER_OF_ITERATIONS; ++j)
{
File hFile = new File("test.txt");
FileWriter stream = new FileWriter(hFile);
stream.write(chars);

stream.close();
}

// Stop timing code

time = System.currentTimeMillis();
float seconds = (time - base) * 0.001f;
System.out.println("Seconds elapsed: " + seconds);
}
}


The way I understand Java is that the java compiler produces bytecodes that are cpu independent. Then there is a virtual machine on top of os that interprets this bytecode and formulates assembly(or binary) code at run time. Am I off base, can someone explain it to me? What''s JIT?

Please understand I''m not bashing languages. I want to use Java but I just don''t know how to drive it optimally. I''m asking people here who know how to drive it optimally that they discuss their timing results compared to both C/C++ AND operating system api methods. We gaveup speed for ease of code understanding when going from assembly to c/c++. I''m willing to give up c/c++ speeds for platform independence but how much speed? That''s what I want to know. Can you quantify.

P.S. I have not seen any Java3D programs so I better check some of them out. I did hear about fullsail''s quake1 port to java but heard people saying it''s old tech. Is someone writing a technology pushing 3D engine with Java. Can you comment?

Share this post


Link to post
Share on other sites
quote:
Original post by JavaJohan
(...) For example, Java is fast on number crunching. (...)



At university, we wrote small programs to manipulate matrices, mostly in java and C/C++. From what I saw, java loses about all it might gain by fast crunching when it comes to memory management. We set loose some rather sloppy algorithms on larger matrices (like 2000x2000). The C programs produced a result after about 10 minutes, the java programs would probably still be running and swapping away if they wouldn''t restart the servers (UltraSPARC 4/400 Enterprise) on a regular basis.

---
rm -rf /
(Best compression everywhere. Kids, don''''t try this as root.)

Share this post


Link to post
Share on other sites
JD...

Ok 381MB''s in 10000 files? Not really realistic but I''ll humor you.

Your results are flawed... for c, and win api as those are probably unflushed streams how else would you explain the win32 api managing to push 238mb/s over a ata100 drive that probably get a maximum of 30mb/s. The same goes for the 42.38mb/s from C it''s buffers could in no way have been completly flushed.

Ok C++ vs Java both of these I''m assuming have been set to 2 byte chars so that 762mb in 10000 file. Not a real fair comparison to the other two, making it push twice as much data?

Now C++ iostreams. I''ll give you the benifit of the doubt that these are 2byte chars. 30 seconds is good at 25mb/s that''s well within reason. Java come in at 15mb/s not too shabby for a slow language. The most lekley reason for the almost half the speed is the double copy that java needs to do to get the char[] into a file, first it needs to be copied into native memory and then copied to a file. This problem will be going away with the new java.nio package due out this year ( 1.4 ), as it will allow java to take advantage of memory mapped io, allowing you to copy directly to OS level disk buffers. This should bring java close to C File speeds.

I''de be glad to give it a shot with java.nio if you really wanted to do the comparison.

So in a way you proved my point that java is not a slow language.

JIT = Just In Time

It''s a refrence to the type of JVM that can compile java byte code to native assembly on the fly to improve performace.

ShadowDancer,

Poorly written code is hardly a good comparison, yes? Especially when you provide us with few other details.

Share this post


Link to post
Share on other sites
Ohh...

And for the most part people in the indusrt know that on average java is about 10% slower than c/c++ at the application level. On the other hand java programing ( for experience developers ) takes 30-50% less time to write and debug than the equivelent c/c++ code.

So you can get 10% faster code by using c/c++ it will just take you 30% longer to market.

Share this post


Link to post
Share on other sites
Ok.. got it for you.. I took your code ( 131 seconds to complete ) and used the performance guide changed 5 lines and now it completes in 20 seconds. That's a 655% speedup.

Here it is.


import java.util.*;
import java.io.*;
public class test
{
public test() { }
public static void main (String args[]) throws IOException
{
final int CHARS_TO_WRITE = 40000;
final int NUMBER_OF_ITERATIONS = 10000;
byte[] chars = new byte[CHARS_TO_WRITE];
for(int i = 0; i < CHARS_TO_WRITE; ++i)
chars = (byte)167;
long base, time;
// Start timing the code
base = System.currentTimeMillis();
for(int j = 0; j < NUMBER_OF_ITERATIONS; ++j)
{
//File hFile = new File("test.txt");
//FileWriter stream = new FileWriter(hFile);
FileOutputStream stream = new FileOutputStream("text.txt");
stream.write(chars);
stream.close();
} // Stop timing code
time = System.currentTimeMillis();
float seconds = (time - base) * 0.001f;
System.out.println("Seconds elapsed: " + seconds); }
}



That would ( if the same sppedup applies ) take your java code to approximatly 7 seconds. Now what was that I was just saying about properly tuned java being very close to C speeds?


Edited by - snowmoon on July 11, 2001 10:48:17 PM

Share this post


Link to post
Share on other sites
Also times can vary wildy by JVM shooping.. here are a few other numbers. My PC is Win2k PIII700 512MB DMA33 HD.

1.4b1 1.3 ibm 1.3
test 130 78 50
modified 22 27 17
Increase 590% 280% 290% Average 390% increace

at 17 seconds thats... 22mb/s not shabby

IBM''s commitment to faster IO ( for servers ) is apparent in how they handle this test.

I think a better test would be to actually write 400mb to the disk and then read it back. The current test gets optimized away in the buffer cache as it only actually writes 40k to disk.

-Eric

Share this post


Link to post
Share on other sites
Snowmoon,

Forgot that char in java was 16bits vs. byte at 8bits. The file for c++ and java was 40Kb but some thunking was probably done to go from word to byte. I rewrote the code and wow what a difference. It takes 4 seconds now vs. 50 seconds. The streams were written to disk whenever the os felt like it.

Thank you for taking your time to correct my code. I appreciate it

Share this post


Link to post
Share on other sites
kvh,

I feel like a fool. I totally missed your post. Thank you for the links I''m going to check them out.

I also want to appologize to the original poster for highjacking his thread. I do thank to all of those who took interest and replied and corrected me. Thanks

Share this post


Link to post
Share on other sites
JD,

Yeah... char are probably written out by using the default char encoding translation. So for each characher it would have to go through an active lookup table. Your mistake is the most common, the simple benchmark is often the most decieving. If you had used a profiler on your code the translation would have stuck out like a sore thumb. This is also the biggest mistake made in graphics programming too, people forgetting to make screen compatible opaque images for there off screen buffers. Then they wonder why it takes soo long to blit them to the screen.

Now when you say 4 seconds, that would make it FASTER than c file, but not as fast a C Win32? That''s even better performance than I would have expected.

Anyways, if you ever find yourself doubting java, just post another question here or at the java forums ( forum.java.sun.com ).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
JD,

Np, I''m new to Java so it was an interesting discussion. Got some good info from it.

Thanks,

Sieggy

Share this post


Link to post
Share on other sites