News for hackers. Stuff that matters.
Re:Show HN: go-nbd – A Pure Go NBD Server and Client by Thaxll on Wednesday March 29, 2023 @02:12PM (#35361032)
You should probably defer mutex unlock() and not use naked returns: https://github.com/pojntfx/go-nbd/blob/main/pkg/backend/file...

Defering overhead is very small nowdays.

Re:Show HN: go-nbd – A Pure Go NBD Server and Client by pojntfx on Wednesday March 29, 2023 @02:15PM (#35361072)
I did think of doing that, but from my understanding there is a slight performance hit from `defer`, and there is no other branch it could deadlock - or am I missing something here? Thanks either way!

Edit: Oh I just saw the addition to your comment - that is exactly what I was thinking of ^^

Re:Show HN: go-nbd – A Pure Go NBD Server and Client by philosopher1234 on Wednesday March 29, 2023 @02:24PM (#35361184)
what about during a panic?
Re:Show HN: go-nbd – A Pure Go NBD Server and Client by pojntfx on Wednesday March 29, 2023 @02:32PM (#35361297)
Good point, thanks!
Re:Show HN: go-nbd – A Pure Go NBD Server and Client by Patrickmi on Wednesday March 29, 2023 @05:20PM (#35363872)
I think there was no performance hit on panic it was memory leak being fixed long time ago
Re:Show HN: go-nbd – A Pure Go NBD Server and Client by foldr on Thursday March 30, 2023 @04:54AM (#35369854)
They mean that the code could deadlock on a panic if the unlock isn't deferred. (At least, in the case where the panic ended up being handled somewhere and the process didn't just exit.)
Re:Show HN: go-nbd – A Pure Go NBD Server and Client by kyrra on Wednesday March 29, 2023 @02:50PM (#35361538)
Defer overhead was mostly fixed in Go 1.14. From: https://go.dev/doc/go1.14

> This release improves the performance of most uses of defer to incur almost zero overhead compared to calling the deferred function directly. As a result, defer can now be used in performance-critical code without overhead concerns.

EDIT: https://github.com/golang/go/issues/14939 I believe is the main tracking bug for this.