olahol / melody

:notes: Minimalist websocket framework for Go
BSD 2-Clause "Simplified" License
3.76k stars 365 forks source link

Is the hub mutex really needed? #22

Closed elimist closed 7 years ago

elimist commented 7 years ago

Hey, thanks for making this library, it's great!

I was wondering: is the mutex here really necessary? It seems the sessions map will never be written to by more than one goroutine and there would probably be some perf gains by removing the lock.

olahol commented 7 years ago

It wasn't needed before the hub.len() method which can read sessions asynchronously. It is probably possible to rewrite it without using locks though.

I answered this before:

https://github.com/olahol/melody/issues/20

elimist commented 7 years ago

Sorry, I missed that issue. That clears it up, thanks!