Skip to content

Commit 9a7f9d8

Browse files
committed
browser: do not allocate buffer on each message write
1 parent 5bb7704 commit 9a7f9d8

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

internal/js/modules/k6/browser/common/connection.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -539,26 +539,13 @@ func (c *Connection) sendLoop() {
539539
for {
540540
select {
541541
case msg := <-c.sendCh:
542-
buf, err := jsonv2.Marshal(msg, defaultJSONV2Options)
543-
if err != nil {
544-
sid := msg.SessionID
545-
tid := c.findTargetIDForLog(sid)
546-
select {
547-
case c.errorCh <- err:
548-
c.logger.Debugf("Connection:sendLoop:c.errorCh <- err", "sid:%v tid:%v wsURL:%q err:%v", sid, tid, c.wsURL, err)
549-
case <-c.done:
550-
c.logger.Debugf("Connection:sendLoop:<-c.done", "sid:%v tid:%v wsURL:%q", sid, tid, c.wsURL)
551-
return
552-
}
553-
}
554-
555-
c.logger.Tracef("cdp:send", "-> %s", buf)
556542
writer, err := c.conn.NextWriter(websocket.TextMessage)
557543
if err != nil {
558544
c.handleIOError(err)
559545
return
560546
}
561-
if _, err := writer.Write(buf); err != nil {
547+
err = jsonv2.MarshalWrite(writer, msg, defaultJSONV2Options)
548+
if err != nil {
562549
c.handleIOError(err)
563550
return
564551
}

0 commit comments

Comments
 (0)