Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  Avoid using objects?  (Read 3490 times)
0 Members and 1 Guest are viewing this topic.
Offline jamdr

Senior Newbie




Java games rock!


« Posted 2005-02-08 23:12:17 »

I'm working on my first major game after a lot of failed, smaller projects. But one thing I learned from those projects is to avoid using objects if at all possible for the best performance. I find myself creating bizarre, sparse, multidimensional arrays instead of using classes like ArrayList and HashMap to gain extra fps. Am I being paranoid? I'm using all standard Java libraries and I never have too many performance problems on Windows, but Macs seem to run my games about 60-70% the speed of PCs, so I need the best performance possible.
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2005-02-08 23:27:42 »

Quote
I'm using all standard Java libraries and I never have too many performance problems on Windows, but Macs seem to run my games about 60-70% the speed of PCs, so I need the best performance possible.


Tuning for fewer object allocations is barking up the wrong tree. Poor performance on the Mac is caused by the Java2D implementation on Mac OS X, not the machine being slower. Apple is aware of the situation, but has deferred fixing it until Java 5.0 (the version that Sun added the OpenGL pipeline).

Java Game Console Project
Last Journal Entry: 12/17/04
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #2 - Posted 2005-02-09 00:43:15 »

In the meantime you can use lwjgl (or jogl for that matter) to get the most drawing speed out of it.

If you only change small sections of the screen (no scrolling) you could also use dirty rectangles (that doesn't make sense with opengl btw).

If you're not satisfied with the performance - don't guess. Profile the application instead. This way you can find the real bottleneck(s).

弾幕 ☆ @mahonnaiseblog
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 2005-02-09 11:59:27 »

You could also simply develop using ArrayList and HashMap to keep things simple and clean, but always use its interfaces to reference them (ie don't reference to ArrayList everywhere but to List).
If, after profiling, the ArrayList turns out to be a bottleneck, implement your own optimized List. I don't think using List instead of raw arrays pose an inherent performance loss, but your code will be cleaner (which is of course especially important with larger projects).

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #4 - Posted 2005-02-09 12:12:20 »

An ArrayList should be just as fast (for the most part) as a regular array. Using the abstract List interface would be worse, as then you've have to use the Iterator methods instead of the familiar for(i etc..) that we all know and love.

But thats probably a red herring. Profile it!

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #5 - Posted 2005-02-09 12:18:04 »

Quote
You could also simply develop using ArrayList and HashMap to keep things simple and clean, but always use its interfaces to reference them (ie don't reference to ArrayList everywhere but to List).
If, after profiling, the ArrayList turns out to be a bottleneck, implement your own optimized List. I don't think using List instead of raw arrays pose an inherent performance loss, but your code will be cleaner (which is of course especially important with larger projects).


How is using a reference to an interface going to improve performance?

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

Jeff:
Unemployed. Wink
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #6 - Posted 2005-02-09 12:31:44 »

Quote
Using the abstract List interface would be worse, as then you've have to use the Iterator methods instead of the familiar for(i etc..) that we all know and love.

Umm, what about List.get(int) ?

Quote
How is using a reference to an interface going to improve performance?

It's not. It's just a way to easily drop in your own optimized List instead of ArrayList later on if necessary, without having to do any refactoring.

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #7 - Posted 2005-02-09 19:54:46 »

I'd recommend rethinking your entire premis; are highlevel data structures ever going to be a bottleneck?  Maybe for something like collision detection among thousands of objects but then you should be using a quad/oct/whatever tree anyway.
Offline jamdr

Senior Newbie




Java games rock!


« Reply #8 - Posted 2005-02-09 22:33:54 »

Thanks for the replies. Since everyone is telling me there must be other problems with my code that have nothing to do with the collection classes I'm using, I will try to profile it and find the bottlenecks. Maybe it's the way I'm using the collections that is the problem.

I'm also thinking my OOP may be causing performance issues. Whenever I draw something to the screen, my game loop tells the manager class which tells an actor class which tells a sprite class to draw itself. The same thing happens when updating game logic. Maybe I should be more "hands-on" with the graphics context. Well, I guess I should go resign myself to the newbie section for a while.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #9 - Posted 2005-02-10 01:19:49 »

Don't feel too bad.
I've been doing Java for quite a while now and I still have issues with parts of my code. Smiley

OOP isn't going to cause you ANY performance decrease.
Java has a hotspot compiler and a JIT compiler.

Hotspot compiler will optimise your program when it loads. It will do things like get rid of dead code and inline methods so you will get no performance hit by using getters or setters.

JIT will further improve performance by optimising your code on the fly which will lead to a further performance increase which are dynamic.

There was an article I was reading which stated that coding procedurally will decrease performance.
If you have properly coded in OOP you will see a performance increase over procedural coding.

Quote
Thanks for the replies. Since everyone is telling me there must be other problems with my code that have nothing to do with the collection classes I'm using, I will try to profile it and find the bottlenecks. Maybe it's the way I'm using the collections that is the problem.

I'm also thinking my OOP may be causing performance issues. Whenever I draw something to the screen, my game loop tells the manager class which tells an actor class which tells a sprite class to draw itself. The same thing happens when updating game logic. Maybe I should be more "hands-on" with the graphics context. Well, I guess I should go resign myself to the newbie section for a while.

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

Jeff:
Unemployed. Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #10 - Posted 2005-02-10 10:41:52 »

I wish we could have parties every now and then where a developer pulls up all their code, everyone profiles it, and everyone searches for things to improve in every aspect of the game Smiley  I know I could use that myself right now Wink

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline jamdr

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-02-14 16:21:19 »

I found the source of my problem: it wasn't using objects that was the problem, it was using 1000s of them per second Wink I was creating just a little garbage in my collision detection routine, but that was easily fixed.

I still find it ridiculous how slow Java2D is on the Mac. I'm getting a max of 1200 FPS on my crap 2.4GHz Dell and only about 150 FPS on my 1GHz eMac.
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #12 - Posted 2005-02-14 17:39:51 »

Quote

Hotspot compiler will optimise your program when it loads. It will do things like get rid of dead code and inline methods so you will get no performance hit by using getters or setters.
JIT will further improve performance by optimising your code on the fly which will lead to a further performance increase which are dynamic.


Wrong - hotspot does what you think the JIT does, but hotspot is the JIT.
All code starts interpreted (very slow) and after a method reached a invoke-threshold (in sun-client 1500) it gets compiled to native code.
Sun is currently working on further dynamic imrpovements, but tiger does'nt do any further optimisations on compiled methods.

lg Clemens
Offline aldacron

Senior Member


Medals: 9
Exp: 16 years


Java games rock!


« Reply #13 - Posted 2005-02-14 23:36:03 »

Quote

I still find it ridiculous how slow Java2D is on the Mac. I'm getting a max of 1200 FPS on my crap 2.4GHz Dell and only about 150 FPS on my 1GHz eMac.


Wow, since when is 150 FPS slow?
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #14 - Posted 2005-02-15 06:12:52 »

Interesting. Thanks.
Reading all those articles people have been talking about JIT as a seperate thing from the hotspot compiler.

So it interprets code for a specific amount of time and then enables JIT? Nice.

Quote


Wrong - hotspot does what you think the JIT does, but hotspot is the JIT.
All code starts interpreted (very slow) and after a method reached a invoke-threshold (in sun-client 1500) it gets compiled to native code.
Sun is currently working on further dynamic imrpovements, but tiger does'nt do any further optimisations on compiled methods.

lg Clemens


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

Jeff:
Unemployed. Wink
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #15 - Posted 2005-02-15 09:15:51 »

Quote

Interesting. Thanks.
Reading all those articles people have been talking about JIT as a seperate thing from the hotspot compiler.

Well, traditional JITs (as the symantec shipped with jdk12, msjvm) compile all and everything at startup).
What the jvm does at class-loading time are some very simply bytecode-optimizatios, but nothing worth to speak about.

Quote

So it interprets code for a specific amount of time and then enables JIT? Nice.

Well, its the best in terms of startup-speed and memory-useage.
One thing which would help this technique would be to save the JIT results (or at least a profile of the last run), but SUN refuses to work on this area steadily - however other VMs creators like Microsoft (with .NET) or BEA (JRockIT) have proofen that this works very well ;-)

lg Clemens
Offline Azeem Jiva

Junior Member




Java VM Engineer, Sun Microsystems


« Reply #16 - Posted 2005-02-15 14:28:00 »

Quote
Interesting. Thanks.
Reading all those articles people have been talking about JIT as a seperate thing from the hotspot compiler.

So it interprets code for a specific amount of time and then enables JIT? Nice.



Correct, in the case of the client compiler its 1500, and for the server compiler its 10,000 invocations.
Offline c_lilian

Senior Member


Projects: 1


Java games will probably rock someday...


« Reply #17 - Posted 2005-02-16 05:08:42 »

Azeem, while you're at it, what can I expect of hotspot server if i create a game (say bubbleracer4k) with only one main method (looping indefinitely with a BufferStrategy to paint results) ?

As it would be a unique method call, could it be optimized ?

Lilian

Offline princec

JGO Kernel


Medals: 391
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #18 - Posted 2005-02-16 06:44:44 »

Yes, Hotspot will optimise the bits in the main method that are called repeatedly in loops.

Cas Smiley

Offline Azeem Jiva

Junior Member




Java VM Engineer, Sun Microsystems


« Reply #19 - Posted 2005-02-16 13:57:58 »

Quote
Yes, Hotspot will optimise the bits in the main method that are called repeatedly in loops.

Cas Smiley



Cas is correct, and depending on how large the methods are that main calls, those will probably get inlined into main as well.
Offline Raghar

Junior Member




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #20 - Posted 2005-02-16 15:08:14 »

So when would be an exe cache in the hotspot?
It's not too difficult, just one interface and SHA 2 hashing. Hotspot is able to do an on stack replacement anyway so it might be included in 1.6 without problems. I really wonder why JVM didn't posted a window with text "Program xxxxx is inicializing: testing xxxx , loading fonts, testing xxxx. transfering control to program"
Then on exit it could post a some window with meaningless statistics.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #21 - Posted 2005-02-18 17:22:03 »

You can get some "meaningless statistics" out of the current hotspot compiler.

-XX:+PrintCompilation  for example will show you what methods are being compiled to native code.

There are other useful bits of information that you can get, some of them require a debug build of hotspot though.

http://java.sun.com/docs/hotspot/VMOptions.html

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #22 - Posted 2005-02-18 17:26:25 »

Quote
I still find it ridiculous how slow Java2D is on the Mac. I'm getting a max of 1200 FPS on my crap 2.4GHz Dell and only about 150 FPS on my 1GHz eMac.


If you can, try running with Java 1.3 on the Mac.  It has a different graphics pipeline.

In 1.4 on the Mac there is NO hardware acceleration of graphics.  the reason being that the core graphics routines in the OS are being optimized to use hardware acceleration for OS X 10.4 (Tiger) as I understand it.   Also the apple Java guys figured on taking advantage of the openGL pipeline in Java 5.   So they conserved their efforts to areas where it would pay off most.. and that basically meant a delay in getting accelerated graphics for java on the Mac.  It does suck, but hopefully it will pay off when 10.4 is released with Java 5.

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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (34 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!