ws icon indicating copy to clipboard operation
ws copied to clipboard

Is it necessary to use sync.Pool to reuse Reader Object in readData?

Open Jekinnnnnn opened this issue 3 years ago • 1 comments

Recently,I used go tool trace to test my project which uses ws v1.0.4.The log shows readData function triggers gc easily when creates "Reader".

runtime.mallocgc:1166
runtime.newobject:1177
github.com/gobwas/ws/wsutil.readData:250
github.com/gobwas/ws/wsutil.ReadData:88
github.com/gobwas/ws/wsutil.ReadClientData:97

In my project,I use a goroutine to recieve remote data.

for {
	select {
	case _, ok := <-c.Stop:
		if !ok {
			return
		}
	default:
		message, msgType, err := websocketUtil.ReadClientData(*c.Conn)
		if err != nil {
			break
		}
		c.Received <- model.ClientMessage{Type: msgType, Data: message}
	}
}

Can optimize performance if use sync.Pool to reuse "Reader"? Reader contains many members,how to reset them properly?

Jekinnnnnn avatar Aug 12 '22 02:08 Jekinnnnnn

I have the same problem as you image

TomYang1024 avatar Sep 02 '22 09:09 TomYang1024