From 94a47d42a788330593b7976f49f8ae733f980db1 Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Fri, 10 Jun 2016 18:20:30 -0500 Subject: [PATCH] Don't defer. This dropped (on my system) the Generate benchmark from about 285-330ns/op down to 244ns/op. Yay! --- snowflake.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/snowflake.go b/snowflake.go index 4ae8db2..ca0b3dd 100644 --- a/snowflake.go +++ b/snowflake.go @@ -54,7 +54,6 @@ func NewNode(node int64) (*Node, error) { func (n *Node) Generate() ID { n.Lock() - defer n.Unlock() now := time.Now().UnixNano() / 1000000 @@ -72,10 +71,13 @@ func (n *Node) Generate() ID { n.time = now - return ID((now-Epoch)<