garbage collection - Using D for a realtime application? -
i considering using d ongoing graphics engine. 1 thing turns me down gc.
i still young programmer , have lot of misconceptions gc's , hope can clarify concerns.
i aiming low latency , timing in general crucial. know gc's pretty unpredictable, example application render frame every 16.6ms , when gc's kicks in go number 30ms because not deterministic right?
i read can turn down gc in d, can't use majority of d's standard library , gc not off. true?
do think makes sense use d in timing crucial application?
short answer: requires lot of customization , can difficult if not experienced d developer.
list of issues:
memory management not big problem. in real-time applications never ever want allocate memory in main loop. having pre-allocated memory pools main data pretty de-facto standard way such applications. in sense, d not different - still call c malloc directly heap pools , memory won't managed gc, won't know it.
however, language features , large parts of phobos use gc automagically. example, can't concatenate slices without form of automatically managed allocation. , phobos has not had strong policy quite long time.
few language-triggered allocations won't problem on own memory used managed via pools anyway. however, there killer issue real-time software in stock d : default d garbage collector stop-the-world. if there no garbage whole program hit latency spike when collection cycle ran, threads blocked.
what can done:
1) use gc.disable();
switch off collection cycles. solve stop-the-world issue program start leak memory in cases, gc-based allocations still work.
2) dump hidden gc allocations. there pull request -vgc
switch can't find right now, in absence can compile own druntime version prints backtrace upon gc_malloc()
call. may want run part of automatic test suite.
3) avoid phobos entirely , use https://bitbucket.org/timosi/minlibd alternative.
doing should enough target soft real-time requirements typical game dev, can see not simple @ , requires stepping out of stock d distribution.
future alternative:
once leandro lucarella ports concurrent garbage collector d2 (which planned, not scheduled), situation become more simple. small amount of gc-managed memory + concurrent implementation allow meet soft real-time requirements without disabling gc. phobos can used after stripped annoying allocations. don't think happen soon.
but hard real-time?
you better not try. yet story tell.
Comments
Post a Comment