Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 8eb70b6

Browse files
committed
Relocate payload in receiver function to avoid copying
1 parent 877bf88 commit 8eb70b6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cmd/goflow/goflow.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/cloudflare/goflow/v3/utils"
1313
"github.com/prometheus/client_golang/prometheus/promhttp"
1414
log "github.com/sirupsen/logrus"
15+
16+
_ "net/http/pprof"
1517
)
1618

1719
var (

utils/utils.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,16 @@ func UDPRoutine(name string, decodeFunc decoder.DecoderFunc, workers int, addr s
189189
}
190190

191191
routine := func(lane int, udpconn *net.UDPConn) {
192-
payload := make([]byte, 9000)
193192
localIP := addrUDP.IP.String()
194193
if addrUDP.IP == nil {
195194
localIP = ""
196195
}
197196

198197
for {
199-
size, pktAddr, _ := udpconn.ReadFromUDP(payload)
200-
payloadCut := make([]byte, size)
201-
copy(payloadCut, payload[0:size])
198+
payload := make([]byte, 9000)
202199

200+
size, pktAddr, _ := udpconn.ReadFromUDP(payload)
201+
payloadCut := payload[0:size]
203202
baseMessage := BaseMessage{
204203
Src: pktAddr.IP,
205204
Port: pktAddr.Port,

0 commit comments

Comments
 (0)