From d770aadee5063ecc54ca8f57fc4906972a2de033 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 4 Aug 2011 08:31:03 -0400 Subject: runtime: faster chan creation on Linux/FreeBSD/Plan9 The change removes chan finalizer (Lock destructor) if it is not required on the platform. benchmark old ns/op new ns/op delta BenchmarkChanCreation 1132.00 381.00 -66.34% BenchmarkChanCreation-2 1215.00 243.00 -80.00% BenchmarkChanCreation-4 1084.00 186.00 -82.84% BenchmarkChanCreation-8 1415.00 154.00 -89.12% BenchmarkChanCreation-16 1386.00 144.00 -89.61% (on 2 x Intel Xeon E5620, 8 HT cores, 2.4 GHz, Linux) R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4841041 --- src/pkg/runtime/chan.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/pkg/runtime/chan.c') diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c index b77e51b60d..65feacb78b 100644 --- a/src/pkg/runtime/chan.c +++ b/src/pkg/runtime/chan.c @@ -85,7 +85,6 @@ runtime·makechan_c(Type *elem, int64 hint) { Hchan *c; int32 n; - byte *by; if(hint < 0 || (int32)hint != hint || (elem->size > 0 && hint > ((uintptr)-1) / elem->size)) runtime·panicstring("makechan: size out of range"); @@ -101,10 +100,9 @@ runtime·makechan_c(Type *elem, int64 hint) n++; // allocate memory in one call - by = runtime·mal(n + hint*elem->size); - - c = (Hchan*)by; - runtime·addfinalizer(c, destroychan, 0); + c = (Hchan*)runtime·mal(n + hint*elem->size); + if(runtime·destroylock) + runtime·addfinalizer(c, destroychan, 0); c->elemsize = elem->size; c->elemalg = &runtime·algarray[elem->alg]; -- cgit v1.3-5-g9baa