From 997c7fce89b34bea869be18be702c79e283d3ab0 Mon Sep 17 00:00:00 2001 From: Reed Allman Date: Wed, 28 Feb 2018 18:35:07 -0800 Subject: [PATCH] fix undefined string slot key (#806) while escape analysis didn't lie that the bytes underlying this string escaped to the heap, the reference to them died and led to us getting an undefined byte array underlying the string. sadly, this makes 4 allocs here (still down from 31), but only adds 100ns per op. I still don't get why 'buf' and 'byts' escape to the heap, blaming faulty escape analysis code. this one is kind of impossible to write a test for. found this from doing benchmarking stuff and was getting weird behavior at the end of runs where calls didn't find a slot, ran bisect on a known-good commit from a couple weeks ago and found that it was this. voila. this could explain the variance from the slack dude's benchmarks, too. anyway, confirmed that this fixes the issue. --- api/agent/slots.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/api/agent/slots.go b/api/agent/slots.go index 6e38cdc35..f3aec0d96 100644 --- a/api/agent/slots.go +++ b/api/agent/slots.go @@ -326,16 +326,11 @@ func getSlotQueueKey(call *call) string { } var buf [sha1.Size]byte - byts := hash.Sum(buf[:0]) - return unsafeString(byts) + hash.Sum(buf[:0]) + return string(buf[:]) } // WARN: this is read only func unsafeBytes(a string) []byte { return *(*[]byte)(unsafe.Pointer(&a)) } - -// WARN: this is read only -func unsafeString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) -}