Performance improvement, avoid create new slice for each Read
Author: ghostCreated Jan 22, 2019Updated Jan 22, 2019
103.60MB 103.60MB (flat, cum) 88.15% of Total
. . 104: }
. . 105: }
. . 106:
. . 107: cipherData := c.readBuf
. . 108: if len(b) > len(cipherData) {
103.60MB 103.60MB 109: cipherData = make([]byte, len(b))
. . 110: } else {
. . 111: cipherData = cipherData[:len(b)]
. . 112: }
. . 113:
. . 114: n, err = c.Conn.Read(cipherData)
(pprof) avoid create new slice for each Read().
cipherData := c.readBuf
if len(b) < len(cipherData) {
cipherData = cipherData[:len(b)]
}Source: shadowsocks/shadowsocks-go