Reduce heap allocations (#42)

* pcap: reuse Frame memory

* slog: reduce heap allocations of addresses; also prevent heap alloc of dhcp options in pcap

* dns: heapless improvement; add StackAsync buffer for more heapless operation; start thinking of errors

* reuse function for reclaiming frames among all protocols for lower memory usage

* remove extraneous code
This commit is contained in:
Pat Whittingslow
2026-02-27 16:38:33 +01:00
committed by GitHub
parent 92b54487df
commit f9748da94f
11 changed files with 198 additions and 130 deletions
+6 -4
View File
@@ -48,6 +48,8 @@ type StackAsync struct {
prng uint32
addrBuf [6]byte // Temporary buffer for As4()/HardwareAddr6() results to avoid heap escapes.
totalsent uint64
totalrecv uint64
}
@@ -353,8 +355,8 @@ func (s *StackAsync) StartLookupIP(host string) error {
if err != nil {
return err
}
dns4 := s.dnssv.As4()
s.dnsUDP.SetStackNode(&s.dns, dns4[:], dns.ServerPort)
*(*[4]byte)(s.addrBuf[:4]) = s.dnssv.As4()
s.dnsUDP.SetStackNode(&s.dns, s.addrBuf[:4], dns.ServerPort)
err = s.udps.Register(&s.dnsUDP)
return err
}
@@ -417,8 +419,8 @@ func (s *StackAsync) StartNTP(addr netip.Addr) error {
defer s.mu.Unlock()
s.ntp.Reset(s.sysprec, time.Now)
addr4 := addr.As4()
s.ntpUDP.SetStackNode(&s.ntp, addr4[:], ntp.ServerPort)
*(*[4]byte)(s.addrBuf[:4]) = addr.As4()
s.ntpUDP.SetStackNode(&s.ntp, s.addrBuf[:4], ntp.ServerPort)
err := s.udps.Register(&s.ntpUDP)
return err
}