fako1024/slimcap

Make afring capture zero-allocating

Closed this issue · 0 comments

Right now there seems to be only a single allocating piece of code in the afring capture source (after initial setup of the ring buffer that is):

      flat  flat%   sum%        cum   cum%
     49153 79.01% 79.01%      49153 79.01%  github.com/fako1024/slimcap/capture/afpacket/afring.(*ringBuffer).nextTPacketHeader /home/fako/Develop/go/pkg/mod/github.com/fako1024/slimcap@v0.0.0-20230517075158-9c3e0d1e0975/capture/afpacket/afring/afring.go:32 (inline)
      4681  7.52% 86.54%       4681  7.52%  regexp/syntax.(*Regexp).Simplify /usr/local/go/src/regexp/syntax/simplify.go:87
      4681  7.52% 94.06%       4681  7.52%  regexp/syntax.(*Regexp).Simplify /usr/local/go/src/regexp/syntax/simplify.go:98

The line in question is simply:

func (b *ringBuffer) nextTPacketHeader() *tPacketHeader {
	return &tPacketHeader{data: b.ring[b.offset*int(b.tpReq.blockSize):]}

Upon each block retrieval a new tPacketHeader is instantiated. However, that's not really required, we can use the data itself to indicate if a new header needs to be retrieved and setup / reuse a single tPacketHeader upon instantiation of the source.