logoalt Hacker News

orf01/21/20251 replyview on HN

No worries, this help also generalises to any time you want to add locking/synchronisation or other overheads to a hot code path.

It’s best not to acquire a mutex and launch a goroutine to read 3 bytes of data at a time.

Also, hot tip: you can like… benchmark this. It’s not illegal.


Replies

bheadmaster01/21/2025

> It’s best not to acquire a mutex and launch a goroutine to read 3 bytes of data at a time.

io.Copy uses 32KB buffers. Other parts of standard library do too. If you're using Read() to read 3 bytes of data at a time, mutex is the least of your worries.

Since you seem to be ignoring sarcasm of my previous comment - just saying "don't do that" without suggesting an alternative way in the particular code context you're referring to, isn't useful at all. It's just annoying.

show 1 reply