From ddab854b9a895603664fa4abfa525f6a29047083 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Mon, 29 Apr 2019 15:32:45 -0700 Subject: Reduce memory allocations on serving path Cache last used messages and reuse them for subsequent requests. If more messages are needed, they are created outside the cache on demand. PiperOrigin-RevId: 245836910 Change-Id: Icf099ddff95df420db8e09f5cdd41dcdce406c61 --- pkg/p9/server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkg/p9/server.go') diff --git a/pkg/p9/server.go b/pkg/p9/server.go index b2a86d8fa..f377a6557 100644 --- a/pkg/p9/server.go +++ b/pkg/p9/server.go @@ -395,7 +395,7 @@ func (cs *connState) handleRequest() { } // Receive a message. - tag, m, err := recv(cs.conn, messageSize, messageByType) + tag, m, err := recv(cs.conn, messageSize, msgRegistry.get) if errSocket, ok := err.(ErrSocket); ok { // Connection problem; stop serving. cs.recvDone <- errSocket.error @@ -458,6 +458,8 @@ func (cs *connState) handleRequest() { // Produce an ENOSYS error. r = newErr(syscall.ENOSYS) } + msgRegistry.put(m) + m = nil // 'm' should not be touched after this point. } func (cs *connState) handleRequests() { -- cgit v1.2.3