Game Development Community

Source code for ObjectPooling test app

by Paul Modzelewski · in Torque X 2D · 03/24/2007 (5:19 am) · 6 replies

Clark, I got the pooling tester working without any of my library calls. It was fairly easy, but a lot of the functionality is simply missing. I included the compiler directive USE_SLATE (the name of my library) that tries to fallback as gracefully as possible when not defined.

A minor inconvenience is that without Configuration, you have to recompile the app to change the config values. The real downside is that there is no logging at all, so there is no way to compare the performance of pooling vs. non-pooling. The hooks are all there, and if there is any kind of logging support on the 360 it should be easy to plug-in. (It might be easiest to simply write text to the screen instead of a log file.)

My library has an excellent little class that wraps QueryPerformanceFrequency / QueryPerformanceCounter for super-hires timing, but I'm pretty sure that isn't available in the .Net CF. DateTime.Now.Ticks has a max. resolution of @50ms, which is too chunky for the kind of performance testing I do here. You'll have to find the equivalent hi-res timer on the 360 (one that gives access to low-level CPU timing).

On the plus side, there is a remote profiling app for XNA 360 that gives even better GC stats than the Windows Performance Counters (what I used to make the perfmon graphs), so you can at least see what the non-generational GC is up too with this test.

Finally, I never thought anybody else would see this code, so I'll apologize up front for how ugly it is. I added comments to all the relevant moving parts, but let me know if you have any questions or problems.

www.paulmodz.net/ObjectPoolTest.zip

#1
03/24/2007 (10:46 am)
Thanks Paul. We'll give this a whirl on the 360 and let you know what it looks like. I'm kind of excited to see the differences between compact and standard frameworks re: object pooling. I'm going to be gone early part of next week, so I won't be able to get back to you right away. But I'll let you know what we find.

BTW, I did do some performance testing in December or so looking at the cost of allocation. I'm not at work right now so I can't look at what I did to jog my memory, but basically I had a single scroller on the screen and then allocated and released (i.e., dereferenced) a bunch of memory every frame and looked at framerate as a function of allocation amount (looking at both max time, avg time, and variance). If I remember correctly, I didn't vary the size of an allocation but rather the number of allocations on a given timestep. I then plotted time cost as a function of allocation rate. The reason I used a scroller was so that I could visually see any hitches going on (but there didn't tend to be hitches with reasonable amounts of allocation so I won't mention it again).

I found that as allocation rate increased the time cost increased (so my manipulation was having an effect) but the cost was surprisingly small. Don't remember the numbers off the top of my head, but if one were to keep allocations under around 2-3 megs/sec it wouldn't really matter re: framerate. On the 360 this was also true, although the cost of allocation was quite a bit higher (several times higher).

If I remember correctly, the max frame rate and variance didn't display any ominous patterns either.

I'll see if I can dig up this data too.
#2
03/24/2007 (2:50 pm)
Cool, I'm looking forward to some numbers from the 360. My guess: The 360's 3GHz triple core CPU and faster memory bus will overcome the lack of GC generations, and like Windows, pooling won't help at all.

One more thing about the code. The PoolTester class (which implements ObjectPooler.IResetable) has a static ctor that loads a text file using a StreamReader. StreamReader is avaiable in .Net CF, so it should work. You'll need to verify that the fileName makes sense to the Xbox, though.

FYI, the static ctor gets called the first time you touch anything in the PoolTester class, before the call you are trying to make. If the file fails to open, the exception is caught by the try-catch in Main() and the app exits. Without logging, it might be annoying to find it.

I have a lot more feedback (and questions), and most are fairly complex like pooling. Since most of these posts are just us back and forth, I'd like the option to talk via e-mail instead of in public sometimes. Does that work for you? (I'll be sure and post anything important that might come up)

If so, should I use the BraveTree address in your profile, or do you have a GG account now?
#3
03/30/2007 (10:20 am)
@Paul - BraveTree email works.
#4
03/30/2007 (2:23 pm)
@Paul - did some quick tests on the PC and the perfmon graphs look the same for both pooling and non-pooling (no logging enabled, so no idea about max frame times). In the other thread you found a different pattern showing up for pooled vs non-pooled. Did you find that same pattern difference using this version of the program (with only short term objects being pooled)? If so, I'm not seeing the same thing.

I need to replace your logging mechanism with a new one so I can see your log messages. Probably won't get to that today though.
#5
04/02/2007 (10:29 am)
@Paul - just to give you an update. We're taking this opportunity to port the Torque Profiler from TGE over to TorqueX. This will allow us to replicate some of your timing logic and get a better comparison of what's happening on the 360 (not to mention helping us in other 360 optimization work). In the meantime I'll be putting this down till we have the profiler completed.
#6
04/02/2007 (11:39 am)
Schweeet! Great news Clark.

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif