From 7f50cf60d3946726f7b91e256528840870aca48a Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Sun, 4 May 2014 09:57:01 -0700 Subject: [PATCH] Don't worry so much about helping the GC Let's just hope the GC does its job correctly and don't try to help it out. This case is probably triggered very infrequently since most people set up their middleware before they accept a single request, and it's worth about 100ns of perf on the common case for us if we get rid of the defer. --- web/middleware.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/web/middleware.go b/web/middleware.go index f9e7963..d39a428 100644 --- a/web/middleware.go +++ b/web/middleware.go @@ -82,12 +82,7 @@ func (m *mStack) findLayer(l interface{}) int { } func (m *mStack) invalidate() { - old := m.pool m.pool = make(chan *cStack, mPoolSize) - close(old) - // Bleed down the old pool so it gets GC'd - for _ = range old { - } } func (m *mStack) newStack() *cStack { @@ -134,13 +129,6 @@ func (m *mStack) release(cs *cStack) { if cs.pool != m.pool { return } - // It's possible that the pool has been invalidated (and closed) between - // the check above and now, in which case we'll start panicing, which is - // dumb. I'm not sure this is actually better than just grabbing a lock, - // but whatever. - defer func() { - recover() - }() select { case cs.pool <- cs: default: