Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Jekinnnnnn opened this issue Aug 12, 2022 · 1 comment
Open

Comments

@Jekinnnnnn
Copy link

Jekinnnnnn commented Aug 12, 2022

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?

@TomYang1024
Copy link

I have the same problem as you
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants