Skip to content

Commit

Permalink
maint: Remove unnecessary fmt.Sprintf usage (#161)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
While doing some profilling with Pyroscope, it was detected fmt.Sprintf
was a causing high memory allocations. Upon reviewing the area, the
structs had a `String()` function we should use instead.

<img width="1638" alt="image"
src="https://github.com/honeycombio/honeycomb-ebpf-agent/assets/3481731/33e9211d-fbbe-4e7b-9121-23ff9fb2c304">


## Short description of the changes
- Replace `fmt.Sprintf` usage with struct's `String()` func

## How to verify that this has the expected result
Memory allocations from using fmt.Sprintf during factory.New calls are
reduced.
  • Loading branch information
MikeGoldsmith authored Sep 11, 2023
1 parent 2e75138 commit be15132
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions assemblers/tcp_stream_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ func (factory *tcpStreamFactory) New(net, transport gopacket.Flow, tcp *layers.T
bytes: make(chan []byte),
parent: stream,
isClient: true,
srcIp: fmt.Sprintf("%s", net.Src()),
dstIp: fmt.Sprintf("%s", net.Dst()),
srcPort: fmt.Sprintf("%s", transport.Src()),
dstPort: fmt.Sprintf("%s", transport.Dst()),
srcIp: net.Src().String(),
dstIp: net.Dst().String(),
srcPort: transport.Src().String(),
dstPort: transport.Dst().String(),
messages: make(chan message, factory.config.ChannelBufferSize),
}
stream.server = httpReader{
bytes: make(chan []byte),
parent: stream,
isClient: false,
srcIp: fmt.Sprintf("%s", net.Reverse().Src()),
dstIp: fmt.Sprintf("%s", net.Reverse().Dst()),
srcPort: fmt.Sprintf("%s", transport.Reverse().Src()),
dstPort: fmt.Sprintf("%s", transport.Reverse().Dst()),
srcIp: net.Reverse().Src().String(),
dstIp: net.Reverse().Dst().String(),
srcPort: transport.Reverse().Src().String(),
dstPort: transport.Reverse().Dst().String(),
messages: make(chan message, factory.config.ChannelBufferSize),
}
factory.wg.Add(2)
Expand Down

0 comments on commit be15132

Please sign in to comment.