kaffiene
|
 |
«
Posted
2005-09-20 06:24:31 » |
|
Hi All
I wrote some code doing a lot of sprite blitting. Works really well - several hundred frames per second using dirty rectangles to avoid complete redraw. Loverly stuff.
The only problem was that I keep getting "jittering" at the start of program execution (performance is stuttery for about first 5-10 seconds). I've traced the GC and see that I get a single long GC then many tiny GC events which should be too swift to notice. I presume that the stuttering in performance that I see is JIT - related.
Is there any way around this? It really ruins the start of my game. I've started coding this up in C++/SDL for comparison - unless I can find some way to avoid what I presume is compilation stalls, I'm going to just go with coding this up in C++.
|
|
|
|
|
Niwak
|
 |
«
Reply #1 - Posted
2005-09-20 07:57:22 » |
|
There are different ways to handle this ; - either you disable JIT compilation with -Xint - either you disable background JIT compilation with -Xbatch - either you force JIT compilation at startup (before your program start) with -Xcompile flag (I'm not sure of the behavior of this flag)
Vincent
|
|
|
|
|
Ken Russell
|
 |
«
Reply #2 - Posted
2005-09-20 08:17:14 » |
|
Which version of the JDK are you using? Are you running the client or server compiler? Which garbage collector are you running? Could you post all of the command line arguments you're passing to the JVM?
Have you tried specifying -XX:-UseThreadPriorities? Does that have any effect?
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
kaffiene
|
 |
«
Reply #3 - Posted
2005-09-20 09:39:24 » |
|
Which version of the JDK are you using? Are you running the client or server compiler? Which garbage collector are you running? Could you post all of the command line arguments you're passing to the JVM?
Have you tried specifying -XX:-UseThreadPriorities? Does that have any effect?
Hi Ken, thanks for tackling this... - JDK version is 1.5.0_04 - Running both server and client JVMs (server by preference) - I've tried standard GC and incgc This is what I'm using at the mo, but I've played with the flags to no avail so far. -ea -server -Xincgc -Xfuture I haven't tried that Thread Priorities flag - I haven't seen it before. I'll give it a go.
|
|
|
|
|
kaffiene
|
 |
«
Reply #4 - Posted
2005-09-20 09:56:10 » |
|
ok, tried the threads flag - doesn't make the problem go
|
|
|
|
|
princec
|
 |
«
Reply #5 - Posted
2005-09-20 10:51:40 » |
|
Try -XX:CompileThreshold=500 Cas 
|
|
|
|
Azeem Jiva
Junior Member  
Java VM Engineer, Sun Microsystems
|
 |
«
Reply #6 - Posted
2005-09-20 16:42:58 » |
|
Try -XX:CompileThreshold=500 Cas  I recommend against that, all that's doing is increasing the number of compiles and probably going to increase the stuttering. You might try -Xbatch to disable background compilation.
|
|
|
|
|
princec
|
 |
«
Reply #7 - Posted
2005-09-20 20:12:42 » |
|
What it'll do is reduce the stuttering to one big pause right at the beginning with any luck. Something else that kaffiene hasn't mentioned is what tech. he's using to do drawing which can have a significant effect on stuttering... Cas 
|
|
|
|
Raghar
Junior Member  
Ue ni taete 'ru hitomi ni kono mi wa dou utsuru
|
 |
«
Reply #8 - Posted
2005-09-20 22:45:20 » |
|
And what about precompile at background when showing a start menu? Playstations used this to make things less painful.
|
|
|
|
|
kaffiene
|
 |
«
Reply #9 - Posted
2005-09-20 23:13:55 » |
|
What it'll do is reduce the stuttering to one big pause right at the beginning with any luck. Something else that kaffiene hasn't mentioned is what tech. he's using to do drawing which can have a significant effect on stuttering... Cas  Good point - I'm using java 2d (drawimage, fillrect), rendering to a single VolatileImage then drawing that to screen.
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
kaffiene
|
 |
«
Reply #10 - Posted
2005-09-20 23:27:50 » |
|
Try -XX:CompileThreshold=500 Cas  Well, that does seem to make it a bit better - at least on my work machine. I'll need to wait till I get home and try it on my development machine to know if it works well enough on slower hardware, but it does look a bit better already (a twitch or two near the start - in the first 2 seconds or so) then apears to run well after that.
|
|
|
|
|
kaffiene
|
 |
«
Reply #11 - Posted
2005-09-20 23:37:35 » |
|
Cas - you're using a compiler for distributing your java games, aren't you? Maybe I should look at static compilation for purposes of comparision (just in case some/all of the stuttering is due to my code rather than the JITter kicking in)
|
|
|
|
|
trembovetski
|
 |
«
Reply #12 - Posted
2005-09-21 07:03:32 » |
|
Have you tried setting a minimum heap size with -Xms to something realistic?
The best way to do this is to run your app with -Xverbose:gc and see what size the heap gets to, and then set it as your min. heap size.
Thanks, Dmitri Java2D Team
|
|
|
|
|
princec
|
 |
«
Reply #13 - Posted
2005-09-21 10:39:22 » |
|
Actually no, I do something mysterious and strange and use a plain old 1.4 client VM for my games (try the Webstart versions, which are virtually identical). I have a feeling your problem is Java2D related, not JIT related, because that's probably the only difference between your game and my games. Your source images might be in system RAM for a few frames and get punted over to VRAM after a short while or something. Cas 
|
|
|
|
kaffiene
|
 |
«
Reply #14 - Posted
2005-09-21 23:11:41 » |
|
Have you tried setting a minimum heap size with -Xms to something realistic?
The best way to do this is to run your app with -Xverbose:gc and see what size the heap gets to, and then set it as your min. heap size.
No, I've left it at the defaults. What's "something realistic"?
|
|
|
|
|
kaffiene
|
 |
«
Reply #15 - Posted
2005-09-21 23:22:11 » |
|
Actually no, I do something mysterious and strange and use a plain old 1.4 client VM for my games (try the Webstart versions, which are virtually identical). I have a feeling your problem is Java2D related, not JIT related, because that's probably the only difference between your game and my games. Your source images might be in system RAM for a few frames and get punted over to VRAM after a short while or something.
Ahh... that's possible - I'm not loading my sprites directly to volatile images, I'm just loading them and using them as plain old BufferedImages. I'll check that out what affect changing that has. BTW: I tried compiling the java with Jet and it did run very smoothly. P.S.: Weren't you arguing against delivering non-compiled Java to people at one stage?
|
|
|
|
|
princec
|
 |
«
Reply #16 - Posted
2005-09-22 00:08:47 » |
|
I never argued against it as such... the problem was a legal issue, which I've sidestepped by, er, compiling the game. Sort of. Cas 
|
|
|
|
kaffiene
|
 |
«
Reply #17 - Posted
2005-09-22 03:41:17 » |
|
I never argued against it as such... the problem was a legal issue, which I've sidestepped by, er, compiling the game. Sort of. Cas  Sounds intriguing  Care to elaborate? At any rate - I switched to loading all the images as volitile images, which seems to have improved things a bit also. I'll check it out on my development machine later tonight.
|
|
|
|
|
princec
|
 |
«
Reply #18 - Posted
2005-09-22 12:11:27 » |
|
Molebox is the solution to your legal woes. It's a compiler. Of sorts. What JVM? Ahem. Cas 
|
|
|
|
Jeff
|
 |
«
Reply #19 - Posted
2005-09-22 18:27:37 » |
|
BTW: I tried compiling the java with Jet and it did run very smoothly.
This begins to soudn an awful lot like start-up issues. Are you running on the server VM? You might try the client for grins. Ist not quite as high peformacne but you may not need that little bit of extra eprformance and it stats up much more smoothly. Otherwise see all the advcie allready given about forcing compile early and "warm up" your system if possible by runnign the render loop for a few seconds without actually rendering.
|
|
|
|
trembovetski
|
 |
«
Reply #20 - Posted
2005-09-22 21:52:07 » |
|
No, I've left it at the defaults. What's "something realistic"?
Here's how to get the most realistic initial vm setting for your game: run it with -verbose:gc and note the heap size when it stabilizes. Then use that value as your initial heap - this will avoid many heap growing/full gc cycles during startup. Thanks, Dmitri Java2D Team
|
|
|
|
|
|