From d512e824a57ab7912ce0c57798a8560479637c10 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Tue, 22 Jun 2010 00:39:50 -0300 Subject: [PATCH 1/1] Comment why we avoid calling free with null Even when free() can be called with a null pointer, the extra call might be significant. On hard GC benchmarks making the test for null in the GC code (i.e. avoiding the free() call) can reduce the GC time by almost ~5%. --- rt/gc/cdgc/bits.d | 4 ++++ rt/gc/cdgc/gc.d | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rt/gc/cdgc/bits.d b/rt/gc/cdgc/bits.d index 02300ce..4d25362 100644 --- a/rt/gc/cdgc/bits.d +++ b/rt/gc/cdgc/bits.d @@ -62,6 +62,10 @@ struct GCBits void Dtor() { + // Even when free() can be called with a null pointer, the extra call + // might be significant. On hard GC benchmarks making the test for null + // here (i.e. not making the call) can reduce the GC time by almost + // ~5%. if (data) { cstdlib.free(data); diff --git a/rt/gc/cdgc/gc.d b/rt/gc/cdgc/gc.d index ee05d60..1e95f06 100644 --- a/rt/gc/cdgc/gc.d +++ b/rt/gc/cdgc/gc.d @@ -1378,12 +1378,15 @@ struct Gcx pool.Dtor(); cstdlib.free(pool); } + + // Even when free() can be called with a null pointer, the extra call + // might be significant. On hard GC benchmarks making the test for null + // here (i.e. not making the call) can reduce the GC time by almost + // ~5%. if (pooltable) cstdlib.free(pooltable); - if (roots) cstdlib.free(roots); - if (ranges) cstdlib.free(ranges); } @@ -2579,6 +2582,7 @@ struct Pool baseAddr = null; topAddr = null; } + // See Gcx.Dtor() for the rationale of the null check. if (pagetable) cstdlib.free(pagetable); -- 2.43.0