Allenxuxu / gev

🚀Gev is a lightweight, fast non-blocking TCP network library / websocket server based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.
MIT License
1.72k stars 193 forks source link

connection.buffer的作用 #110

Closed HypenZou closed 2 years ago

HypenZou commented 2 years ago

谢谢作者的开源框架, 最近在学习, 问个小细节 https://github.com/Allenxuxu/gev/blob/b8a69c7227b5a6cba2c890180b188585ee7e70bb/connection.go#L226

69 optimize performance & update benchmarks中将局部变量buffer改成了connection中的一个固定属性buffer, 请问这样有什么性能上的优势吗?

局部变量buffer也只是一个小的结构体, 里面的buf是用ringbuffer.NewWithData绑定到loop的临时缓冲区packet上的, 没有额外的内存开销和拷贝, 所以这个地方的改动我有点不太清楚意义所在, 反而connection多了一个buffer字段初看有点不明所以。

Allenxuxu commented 2 years ago

这里就是为了复用这个 struct