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

NRG: Reduce sendq allocations #6132

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions server/sendq.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (sq *sendq) internalLoop() {
rply [256]byte
szb [10]byte
hdb [10]byte
_msg [4096]byte
msg = _msg[:0]
)

for s.isRunning() {
Expand All @@ -74,16 +76,18 @@ func (sq *sendq) internalLoop() {
} else {
c.pa.reply = nil
}
var msg []byte
msg = msg[:0]
derekcollison marked this conversation as resolved.
Show resolved Hide resolved
if len(pm.hdr) > 0 {
c.pa.hdr = len(pm.hdr)
c.pa.hdb = append(hdb[:0], strconv.Itoa(c.pa.hdr)...)
msg = append(pm.hdr, pm.msg...)
msg = append(msg, pm.hdr...)
msg = append(msg, pm.msg...)
msg = append(msg, _CRLF_...)
} else {
c.pa.hdr = -1
c.pa.hdb = nil
msg = append(pm.msg, _CRLF_...)
msg = append(msg, pm.msg...)
msg = append(msg, _CRLF_...)
}
c.processInboundClientMsg(msg)
c.pa.szb = nil
Expand All @@ -108,16 +112,7 @@ func (sq *sendq) send(subj, rply string, hdr, msg []byte) {
}
out := outMsgPool.Get().(*outMsg)
out.subj, out.rply = subj, rply
out.hdr, out.msg = nil, nil

// We will copy these for now.
if len(hdr) > 0 {
hdr = copyBytes(hdr)
out.hdr = hdr
}
if len(msg) > 0 {
msg = copyBytes(msg)
out.msg = msg
}
out.hdr = append(out.hdr[:0], hdr...)
out.msg = append(out.msg[:0], msg...)
sq.q.push(out)
}