proposal: GC.*partial*collect(Duration maxPauseTime, Duration maxCollectionTime)

mw mingwu at gmail.com
Tue May 19 05:42:29 UTC 2020


Hi,

I'm new to D(2). Have spent past week reading a lot about other 
people's articles on D, pros & cons, etc. One of the things 
people have talked about alot is the slow gc, esp. in a 
multi-threaded env, real-time system, or interactive games dev.

OK, gc has its problem, but most programs cannot do without it 
(nogc phobos not there yet). Actually the programmer knows best 
*when & where* in his/her program, s/he can manually call 
gc.collect() to free resource. But currently gc.collect() will do 
a full collection:

https://dlang.org/library/core/memory/gc.collect.html

which is unpredictable how long it will take. In real-time 
systems this is not acceptable. The programmer will still 
hesitate to call gc.collect().

So we want a predictable gc: I just had a simple idea to improve 
the usability of current gc implementation (probably with minimal 
code change). My idea is add parameters to the gc.collect():

GC.*partial*collect(Duration maxPauseTime, Duration 
maxCollectionTime)

and ask it to do a partial collection. The parameters are defined 
here :-)

https://dlang.org/library/core/memory/gc.profile_stats.html

Name	Type	Description
maxCollectionTime	Duration	largest time spent doing one GC cycle
maxPauseTime		Duration	largest time threads were paused during 
one GC cycle


Now, the gc is much controllable in real-time systems.

Thoughts?



More information about the Digitalmars-d mailing list