reduce calls to time.Now() calls in connection (#4191)

This commit is contained in:
Benedikt Spies 2023-12-06 15:00:58 +01:00 committed by GitHub
parent 87ef8ec48d
commit 45922f76d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -629,7 +629,7 @@ runLoop:
sendQueueAvailable = s.sendQueue.Available()
continue
}
if err := s.triggerSending(); err != nil {
if err := s.triggerSending(now); err != nil {
s.closeLocal(err)
}
if s.sendQueue.WouldBlock() {
@ -1767,9 +1767,8 @@ func (s *connection) applyTransportParameters() {
}
}
func (s *connection) triggerSending() error {
func (s *connection) triggerSending(now time.Time) error {
s.pacingDeadline = time.Time{}
now := time.Now()
sendMode := s.sentPacketHandler.SendMode(now)
//nolint:exhaustive // No need to handle pacing limited here.
@ -1801,7 +1800,7 @@ func (s *connection) triggerSending() error {
s.scheduleSending()
return nil
}
return s.triggerSending()
return s.triggerSending(now)
case ackhandler.SendPTOHandshake:
if err := s.sendProbePacket(protocol.EncryptionHandshake, now); err != nil {
return err
@ -1810,7 +1809,7 @@ func (s *connection) triggerSending() error {
s.scheduleSending()
return nil
}
return s.triggerSending()
return s.triggerSending(now)
case ackhandler.SendPTOAppData:
if err := s.sendProbePacket(protocol.Encryption1RTT, now); err != nil {
return err
@ -1819,7 +1818,7 @@ func (s *connection) triggerSending() error {
s.scheduleSending()
return nil
}
return s.triggerSending()
return s.triggerSending(now)
default:
return fmt.Errorf("BUG: invalid send mode %d", sendMode)
}
@ -1988,7 +1987,7 @@ func (s *connection) maybeSendAckOnlyPacket(now time.Time) error {
if packet == nil {
return nil
}
return s.sendPackedCoalescedPacket(packet, ecn, time.Now())
return s.sendPackedCoalescedPacket(packet, ecn, now)
}
ecn := s.sentPacketHandler.ECNMode(true)