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
{
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");
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];
func BenchmarkChanProdConsWork100(b *testing.B) {
benchmarkChanProdCons(b, 100, 100)
}
+
+func BenchmarkChanCreation(b *testing.B) {
+ const CallsPerSched = 1000
+ procs := runtime.GOMAXPROCS(-1)
+ N := int32(b.N / CallsPerSched)
+ c := make(chan bool, procs)
+ for p := 0; p < procs; p++ {
+ go func() {
+ for atomic.AddInt32(&N, -1) >= 0 {
+ for g := 0; g < CallsPerSched; g++ {
+ myc := make(chan int, 1)
+ myc <- 0
+ <-myc
+ }
+ }
+ c <- true
+ }()
+ }
+ for p := 0; p < procs; p++ {
+ <-c
+ }
+}
}
}
-void
-runtime·destroylock(Lock *l)
+static void
+destroylock(Lock *l)
{
if(l->sema != 0) {
runtime·mach_semdestroy(l->sema);
// to let the C pthread libary install its own thread-creation callback.
if(!runtime·iscgo)
runtime·bsdthread_register();
+ runtime·destroylock = destroylock;
}
void
umtx_unlock(l);
}
-void
-runtime·destroylock(Lock*)
-{
-}
-
// Event notifications.
void
runtime·noteclear(Note *n)
futexunlock(l);
}
-void
-runtime·destroylock(Lock*)
-{
-}
-
// One-time notifications.
void
}
-void
-runtime·destroylock(Lock *l)
-{
- // nothing
-}
-
// User-level semaphore implementation:
// try to do the operations in user space on u,
// but when it's time to block, fall back on the kernel semaphore k.
};
uint32 runtime·panicking;
+void (*runtime·destroylock)(Lock*);
/*
* We assume that all architectures turn faults and the like
extern int32 runtime·gcwaiting; // gc is waiting to run
int8* runtime·goos;
extern bool runtime·iscgo;
+extern void (*runtime·destroylock)(Lock*);
/*
* common functions and data
*/
void runtime·lock(Lock*);
void runtime·unlock(Lock*);
-void runtime·destroylock(Lock*);
/*
* sleep and wakeup on one-time events.
extern void *runtime·WriteFile;
static int64 timerfreq;
+static void destroylock(Lock *l);
void
runtime·osinit(void)
{
runtime·stdcall(runtime·QueryPerformanceFrequency, 1, &timerfreq);
runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (uintptr)1);
+ runtime·destroylock = destroylock;
}
void
eventunlock(l);
}
-void
-runtime·destroylock(Lock *l)
+static void
+destroylock(Lock *l)
{
if(l->event != 0)
runtime·stdcall(runtime·CloseHandle, 1, l->event);