optimize window update generation, reducing profiler footprint by 8%

This commit is contained in:
Lucas Clemente
2016-09-15 09:10:59 +02:00
parent 7bd4d0852c
commit 2592b9a97c
5 changed files with 38 additions and 50 deletions

View File

@@ -106,25 +106,15 @@ func (f *flowControlManager) AddBytesRead(streamID protocol.StreamID, n protocol
return nil
}
// streamID must not be 0 here
func (f *flowControlManager) MaybeTriggerStreamWindowUpdate(streamID protocol.StreamID) (bool, protocol.ByteCount, error) {
func (f *flowControlManager) GetWindowUpdates() (res []WindowUpdate) {
f.mutex.Lock()
defer f.mutex.Unlock()
streamFlowController, err := f.getFlowController(streamID)
if err != nil {
return false, 0, err
for id, fc := range f.streamFlowController {
if necessary, offset := fc.MaybeTriggerWindowUpdate(); necessary {
res = append(res, WindowUpdate{StreamID: id, Offset: offset})
}
}
doIt, offset := streamFlowController.MaybeTriggerWindowUpdate()
return doIt, offset, nil
}
func (f *flowControlManager) MaybeTriggerConnectionWindowUpdate() (bool, protocol.ByteCount) {
f.mutex.Lock()
defer f.mutex.Unlock()
return f.streamFlowController[0].MaybeTriggerWindowUpdate()
return res
}
// streamID must not be 0 here

View File

@@ -95,10 +95,10 @@ var _ = Describe("Flow Control Manager", func() {
Expect(err).ToNot(HaveOccurred())
err = fcm.AddBytesRead(4, 0x100-0x10)
Expect(err).ToNot(HaveOccurred())
doIt, offset, err := fcm.MaybeTriggerStreamWindowUpdate(4)
Expect(err).ToNot(HaveOccurred())
Expect(doIt).To(BeTrue())
Expect(offset).ToNot(Equal(protocol.ByteCount(0x100)))
updates := fcm.GetWindowUpdates()
Expect(updates).To(HaveLen(1))
Expect(updates[0].StreamID).To(Equal(protocol.StreamID(4)))
Expect(updates[0].Offset).To(Equal(protocol.ByteCount(0x1f0)))
})
It("gets connection level window updates", func() {
@@ -110,10 +110,15 @@ var _ = Describe("Flow Control Manager", func() {
Expect(err).ToNot(HaveOccurred())
err = fcm.AddBytesRead(6, 0x100-0x10)
Expect(err).ToNot(HaveOccurred())
doIt, offset := fcm.MaybeTriggerConnectionWindowUpdate()
Expect(err).ToNot(HaveOccurred())
Expect(doIt).To(BeTrue())
Expect(offset).ToNot(Equal(protocol.ByteCount(0x200)))
updates := fcm.GetWindowUpdates()
Expect(updates).To(HaveLen(3))
if updates[0].StreamID == 0 {
Expect(updates[0].Offset).ToNot(Equal(protocol.ByteCount(0x200)))
} else if updates[1].StreamID == 0 {
Expect(updates[1].Offset).ToNot(Equal(protocol.ByteCount(0x200)))
} else {
Expect(updates[2].Offset).ToNot(Equal(protocol.ByteCount(0x200)))
}
})
})
})

View File

@@ -2,6 +2,12 @@ package flowcontrol
import "github.com/lucas-clemente/quic-go/protocol"
// WindowUpdate provides the data for WindowUpdateFrames.
type WindowUpdate struct {
StreamID protocol.StreamID
Offset protocol.ByteCount
}
// A FlowControlManager manages the flow control
type FlowControlManager interface {
NewStream(streamID protocol.StreamID, contributesToConnectionFlow bool)
@@ -9,8 +15,7 @@ type FlowControlManager interface {
// methods needed for receiving data
UpdateHighestReceived(streamID protocol.StreamID, byteOffset protocol.ByteCount) error
AddBytesRead(streamID protocol.StreamID, n protocol.ByteCount) error
MaybeTriggerStreamWindowUpdate(streamID protocol.StreamID) (bool, protocol.ByteCount, error)
MaybeTriggerConnectionWindowUpdate() (bool, protocol.ByteCount)
GetWindowUpdates() []WindowUpdate
// methods needed for sending data
AddBytesSent(streamID protocol.StreamID, n protocol.ByteCount) error
SendWindowSize(streamID protocol.StreamID) (protocol.ByteCount, error)