Incremental garbage collection
rtcvb32 at yahoo.com
Fri Jan 21 17:43:36 UTC 2022
On Thursday, 20 January 2022 at 23:56:42 UTC, Chris Katko wrote:
> I just found out that Unity has incremental garbage collection.
> I didn't know that was a possibility for GCs.
> I'm just curious what the D language community's thoughts are
> on it. The tradeoff is: For a longer total time / lower
> throughput, you reduce stress on individual frames which
> prevents hiccups. That's pretty darn important for games and
> soft/hard real-time systems.
I would say it really depends on a handful of things, like how
much allocating/deallocating you're actually doing, and if
fragmentation or things would be the issue and if doing it more
often would help. I try to write code using the stack rather than
allocating for small temporary items which frees itself when it
leaves the function.
Though, having the GC pick up while waiting on the OS to reply
would be a great time to do it's work; that would be the best
time to work.
As for handling fragmentation, I'd almost wish to make a
different type of allocator which gives you an id and you use the
id+offset to get the actual address (*though to make it work it
would be a new type of slice that would handle those details
transparently*); Then periodically (*say every 50ms or
something*) it would do a quick check/scan for a hole, and then
move data and adjust the values of said id's to remove empty
holes and make it as tight as possible.
I'm also not sure how well it would work on multi-threaded
applications, though having locks which the GC locks the id's
while it moves them and then unlocks *should* handle those
This of course only would be needed if you have
limited/preallocated memory and fragmentation (*due to some parts
being too small*) could kill the process. Otherwise it would
probably be a lot of busywork.
To note while i love contemplating this stuff, I'm not quite sure
how to implement it all myself. I don't have the same mental
fortitude i had when i was 14.
More information about the Digitalmars-d