I was thinking of how the GC could be optimized further and came across some sweet flags that are barely used throughout Phobos in favor of a witch-hunting against the GC:

GC.BlkAttr.NO_SCAN
GC.BlkAttr.NO_INTERIOR

When using the NO_SCAN attribute with GC.setAttr(p, NO_SCAN), you're basically doing removeRange on a GC allocation. It's never going to scan the memory in it, but the memory will stay alive if pointers are found pointing to anything inside it. This is very useful for strings! But I can't even find an example of a string with this flag. I'm totally baffled.

When using NO_INTERIOR attribute, you're telling the GC that nothing can point to the inside of the allocation if it's bigger than 4096 bytes, and to completely ignore scanning its contents in such case.

With these 2 attributes, one could write a simple recursive function in phobos that adjusts the flags on an object's allocations based on the type info.

Tuple!(int, int, int, string)[] bigTupleArray;
bigTupleArray.optimizeGC(); // sets NO_SCAN on ints, and on the pointee of string

Thoughts?

Reply via email to