Jump to content
  • Advertisement
Sign in to follow this  
sinergitized

C++ garbage collection performance

This topic is 4885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm doing my engine closely tied with Hans Boehm's Garbage Collector. This was an experiment (garbage collection, full reflection, automatic serialization... in C++). I've implemented all of the gritty details of the Core system, and I'm a bit worried becouse of performance. Has anyone else used this kind of scheme? What are your experiences with GC (esp. with C++). Since C# and Java have a GC, and some games are written in it, and some tests show that there isn't much of a difference in code execution speed, I would assume it's sound to make an engine with GC? Any thoughts?

Share this post


Link to post
Share on other sites
Advertisement
Nice paper, I got quite some info, but I must admit I was more looking forward to some hand on first person experiences, observations and the like. Since the engine pretty much resembles Unreal in OOP and amount of objects, I gather it's probably gonna beat the GC to death (about 400.000 references, and about 50.000 objects live at the same time, about 400 megs memory consumption) - these are just my speculations (and expectations) and are thus far from some solid performance info.

Share this post


Link to post
Share on other sites
In C++ you can combine automatic and manual heap management. In cases where it is hard to determine when an object may be deleted and from which instance, a GC fits very well. In cases where the objects come and go, i.e. a particle generator, manual memory management may be the better choice.

It is also possible to avoid a full blown GC and just use reference counting. This works very well as long as you do not use cyclic data structures.

A word about speed:
When using great amounts of memory (400 megs you said), a generational GC would be required. This keeps the collected area small and within the same pages of virtual memory. I think the paper explains this very well.
Also implementing a special purpose GC for your engine might give a big performance increase. Boehm's GC is just too conservative.

Some people even claim a GC may increase performance, since memory allocation is as cheap as incrementing a pointer and freeing the memory is done in times where the CPU is idle.

Share this post


Link to post
Share on other sites
You might want to take a gander at the Digital Mars site. The DM C/C++ compiler ships with the Boehm Collector, and the official implementation of the D Programming Language (also by Digital Mars) uses Boehm with excellent results. I mention this because you may be able to get some good info on GC in general and Boehm specifically at the Digital Mars C++ or D newsgroups.

Share this post


Link to post
Share on other sites
Okay, I've measured some things today and, indeed, with no static roots enabled, and with incremental collection, the GC performs very very well. I've converted a big app I had (deleted all the delete statements :P ) at the ready and it didn't perform worse at all. The memory consumption was almost 2x the normal size, however :( but I anticipated that (with my 400 megs claim) but it was still something hard to admit.

What should I use as a starting point if I would do my own GC? Should I dismantle Boehm's GC and seek out where I could add customised code?

Thanks a lot.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!