From c8ba155d47567b871f4e3f15927a6c8488e9355c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 8 Oct 2020 16:29:30 +0300 Subject: [PATCH] server: don't always Sprintf params for logger Add Stringer to Params, if we're not printing Debug messages (which usually is the case), it won't be called at all. Micro-optimization. --- pkg/rpc/request/params.go | 6 ++++++ pkg/rpc/server/server.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/rpc/request/params.go b/pkg/rpc/request/params.go index dd2ac35b9..c35e13b43 100644 --- a/pkg/rpc/request/params.go +++ b/pkg/rpc/request/params.go @@ -1,5 +1,7 @@ package request +import "fmt" + type ( // Params represents the JSON-RPC params. Params []Param @@ -23,3 +25,7 @@ func (p Params) ValueWithType(index int, valType paramType) *Param { } return nil } + +func (p Params) String() string { + return fmt.Sprintf("%v", []Param(p)) +} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 9db856dda..1b7ed7228 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -291,7 +291,7 @@ func (s *Server) handleRequest(req *request.In, sub *subscriber) response.Abstra s.log.Debug("processing rpc request", zap.String("method", req.Method), - zap.String("params", fmt.Sprintf("%v", reqParams))) + zap.Stringer("params", reqParams)) incCounter(req.Method)