Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (472)
Games in Android Showcase (105)
games submitted by our members
Games in WIP (524)
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  
  Performance with very large object counts  (Read 1918 times)
0 Members and 1 Guest are viewing this topic.
Offline rkwright

Senior Newbie





« Posted 2008-08-11 23:36:37 »

I wrote a small set of utilities in JOGL that implement 2D PostScript rendering in 3D space, i.e. implemented most of the PostScript path and graphics state operators. So you can create a path  and then stroke (including dash, joins, caps, etc.) and fills.  Kind of fun.  I think this my fourth PS implementation but definitely the first in Java. The resulting path can be rendered in 2D or extruded to make a filled shape.  It works very nicely, but then I ran into a problem.

I wrote a simple temperature wave simulation that shows the variation of temperature with depth in the ground, both vertically and over time.  Then I run the simulation. Problem is that it generates a LOT of objects, e.g. 300 data points at 10 depths results in 300x10*4 objects. At a modest 20 FPS, this generates 240,000 objects a second.  It can run at 35 FPS initially, but after a little while it starts pausing and the rate drops to 10 FPS (QuadCore MacPro).

None of the cores are maxed, so my thought is that it is GC as the heap gets fragmented.  I assume it is not GPU bound as I can't see why it would be.  I've done a little dumping of the GC data (gc:verbose) but that doesn't seem to tell me much.

Thoughts? Comments?  Am I missing something?  I am no Java maven so that is entirely possible.
Offline princec

JGO Kernel


Medals: 333
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2008-08-12 00:41:14 »

Well - what is the output of gc:verbose?

And at any rate: 250k objects a second is way too much garbage to create for smooth client operation; you're going to start looking into object reuse and pooling to get that down to, say, 100th of the amount.

Cas Smiley

Offline rkwright

Senior Newbie





« Reply #2 - Posted 2008-08-12 00:58:52 »

I agree that 250k/s is way too much and I am looking at how to minimize that. That being said, I guess I may also have to learn more than I want about how the GC works in general.  I was hoping that there might be an easier way, being the lazy person that I am - or at least I would prefer to spend my time on more interesting tasks than memory management in Java.

Also, some of it is not in my control as it is in the generation of the paths themselves, which are GeneralPaths.  But I am looking at how I can avoid that as well.
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 2008-08-12 09:54:27 »

If you want to learn more about GC, this is a good resource:
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

I doubt that you can tune any GC to efficiently handle 250k objects of garbage a second though, so you probably might want to introduce some pooling, or maybe you can apply the flyweight pattern somewhere to reduce garbage.

Offline rkwright

Senior Newbie





« Reply #4 - Posted 2008-08-12 14:46:23 »

Thanks for the feedback.  As is often the case, when I thought about it some more and turned the problem on its side, the right path (so to speak ;-) was apparent.  I have written the pooling object to handle all the elements I need to manage.  Now I need to retrofit the existing code to use the new constructs.  One of the consequences is that I had to abandon using GeneralPath and use my own path object for everything, so I also had to write a Bezier flattener, but that's no big deal - been there, done that. I had already written the rest of the Bezier support, anyway.  But I learned some more about Java and GC, which is always good.
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.

Riven (5 views)
2014-07-10 18:29:06

Riven (17 views)
2014-07-10 14:55:47

CopyableCougar4 (15 views)
2014-07-10 02:26:14

CopyableCougar4 (25 views)
2014-07-09 02:55:38

Code Mage (24 views)
2014-07-08 23:57:00

Code Mage (10 views)
2014-07-08 23:49:08

AppleSauce (20 views)
2014-07-08 19:25:32

CopyableCougar4 (21 views)
2014-07-06 01:51:26

ipe369 (26 views)
2014-07-05 14:18:25

vastrolorde (37 views)
2014-07-04 18:45:44
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!