diff --git a/packet_unpacker.go b/packet_unpacker.go index 95b9d4f79..1e1682dce 100644 --- a/packet_unpacker.go +++ b/packet_unpacker.go @@ -37,7 +37,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, r } entropyBit := privateFlag&0x01 > 0 - fs := []frames.Frame{} + fs := make([]frames.Frame, 0, 1) // Read all frames in the packet ReadLoop: diff --git a/session.go b/session.go index 7c0bbc285..206c67c9b 100644 --- a/session.go +++ b/session.go @@ -545,6 +545,10 @@ func (s *Session) sendConnectionClose(quicErr *qerr.QuicError) error { } func (s *Session) logPacket(packet *packedPacket) { + if !utils.Debug() { + // We don't need to allocate the slices for calling the format functions + return + } utils.Debugf("-> Sending packet 0x%x (%d bytes)", packet.number, len(packet.raw)) for _, frame := range packet.frames { if streamFrame, isStreamFrame := frame.(*frames.StreamFrame); isStreamFrame { diff --git a/utils/log.go b/utils/log.go index 864a48956..c82f6f477 100644 --- a/utils/log.go +++ b/utils/log.go @@ -58,3 +58,8 @@ func Errorf(format string, args ...interface{}) { mutex.Unlock() } } + +// Debug returns true if the log level is LogLevelDebug +func Debug() bool { + return logLevel == LogLevelDebug +}