On 22.05.2014 18:42, Etienne wrote:
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?
rt.lifetime makes heavy use of "NO_SCAN" for all array handling (including strings). It uses the compiler generated flag inside the TypeInfo. Classes also deal with this flag (see _d_newclass).
I'm not sure where allocating a struct ends up, so maybe there is some potential there.
"NO_INTERIOR" is currently only used for the hash array used by associative arrays. It is a bit dangerous to use as any pointer,slice or register still operating on the array is ignored, so collecting it might corrupt your memory.
