Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 2798 times)
0 Members and 1 Guest are viewing this topic.
Offline rkwright

Senior Newbie

« Posted 2008-08-11 21: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 Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #1 - Posted 2008-08-11 22: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-11 22: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


« Reply #3 - Posted 2008-08-12 07:54:27 »

If you want to learn more about GC, this is a good resource:

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 12: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  

EgonOlsen (76 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (256 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!