#1142·nakama

Optimizing Performance in Message Broadcasting for sessionWS

Author: huangzzCreated Nov 15, 2023Updated Apr 6, 2026

In sessionWS, the sending of messages is synchronized using sync.Mutex. This has a significant performance impact when there is a need for broadcasting in the game.

SendBytes and processOutgoing currently use channels for communication, and in fact, locks are not necessary. The only places where locks may be needed are in the WriteMessage function in processOutgoing and SendBytes.

It is recommended to remove unnecessary locks in these functions. This would lead to significant performance improvements in projects such as MMOs that require a large amount of broadcasting.