December 02, 2008
Since resource contention for memory allocations seems to be a big issue in D, at least for me, and memory allocation is usually pretty fast, would it make sense to make the lock used for GC.malloc a spinlock?  Since memory allocation takes very little time relative to a full timeslice, there is likely to be very little contention for malloc on a single-processor machine.  This means that a thread will very seldom be left spinning until its timeslice is up.  I believe (correct me if I'm wrong) that the kernel call, etc. for a full lock takes longer than a memory allocation from the GC pool.  This makes the locking in truly parallel multiprocessor code a significant bottleneck.  Of course, if the GC needs to free memory, not just allocate from its available pool, the spinlock should ideally inflate to a full lock.  Does this sound reasonable/implementable?