implement a memory-optimized time.Time replacement (#5334)

* implement a memory-optimized time.Time replacement

* monotime: properly handle systems with bad timer resolution (Windows)

* monotime: simplify Since
This commit is contained in:
Marten Seemann
2025-09-14 14:12:10 +08:00
committed by GitHub
parent f61188b8ff
commit adc13be540
75 changed files with 1003 additions and 797 deletions

View File

@@ -9,6 +9,7 @@ import (
"sync"
"time"
"github.com/quic-go/quic-go/internal/monotime"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/utils"
)
@@ -27,7 +28,7 @@ type connection struct {
Outgoing *queue
}
func (c *connection) queuePacket(t time.Time, b []byte) {
func (c *connection) queuePacket(t monotime.Time, b []byte) {
c.incomingPackets <- packetEntry{Time: t, Raw: b}
}
@@ -60,7 +61,7 @@ const (
)
type packetEntry struct {
Time time.Time
Time monotime.Time
Raw []byte
}
@@ -286,7 +287,7 @@ func (p *Proxy) runProxy() error {
return err
}
} else {
now := time.Now()
now := monotime.Now()
if p.logger.Debug() {
p.logger.Debugf("delaying incoming packet (%d bytes) to %s by %s", len(raw), conn.ServerAddr, delay)
}
@@ -331,7 +332,7 @@ func (p *Proxy) runOutgoingConnection(conn *connection) error {
return
}
} else {
now := time.Now()
now := monotime.Now()
if p.logger.Debug() {
p.logger.Debugf("delaying outgoing packet (%d bytes) to %s by %s", len(raw), conn.ClientAddr, delay)
}

View File

@@ -7,6 +7,7 @@ import (
"testing"
"time"
"github.com/quic-go/quic-go/internal/monotime"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/wire"
@@ -25,7 +26,7 @@ func TestPacketQueue(t *testing.T) {
}
require.Empty(t, getPackets())
now := time.Now()
now := monotime.Now()
q.Add(packetEntry{Time: now, Raw: []byte("p3")})
require.Equal(t, []string{"p3"}, getPackets())