Skip to content

Commit

Permalink
Skip useless delta updates – send full payload instead (#388)
Browse files Browse the repository at this point in the history
If the size of delta patch is greater or equal than full publication payload – skip sending delta, just use the full payload.
  • Loading branch information
FZambia committed Jun 9, 2024
1 parent c5fffda commit f41c0bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
31 changes: 14 additions & 17 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3038,24 +3038,21 @@ func (c *Client) makeRecoveredPubsDeltaFossil(recoveredPubs []*protocol.Publicat
if len(recoveredPubs) > 1 {
for i, pub := range recoveredPubs[1:] {
patch := fdelta.Create(prevPub.Data, pub.Data)
var deltaPub *protocol.Publication
delta := true
deltaData := patch
if len(patch) >= len(pub.Data) {
delta = false
deltaData = pub.Data
}
if c.transport.Protocol() == ProtocolTypeJSON {
// For JSON case we need to use JSON string (js) for patch.
deltaPub = &protocol.Publication{
Offset: pub.Offset,
Data: json.Escape(convert.BytesToString(patch)),
Info: pub.Info,
Tags: pub.Tags,
Delta: true,
}
} else {
deltaPub = &protocol.Publication{
Offset: pub.Offset,
Data: patch,
Info: pub.Info,
Tags: pub.Tags,
Delta: true,
}
deltaData = json.Escape(convert.BytesToString(deltaData))
}
deltaPub := &protocol.Publication{
Offset: pub.Offset,
Data: deltaData,
Info: pub.Info,
Tags: pub.Tags,
Delta: delta,
}
recoveredPubs[i+1] = deltaPub
prevPub = recoveredPubs[i]
Expand Down
29 changes: 14 additions & 15 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,22 +582,21 @@ func getDeltaPub(prevPub *Publication, fullPub *protocol.Publication, key prepar
deltaPub := fullPub
if prevPub != nil && key.DeltaType == DeltaTypeFossil {
patch := fdelta.Create(prevPub.Data, fullPub.Data)
delta := true
deltaData := patch
if len(patch) >= len(fullPub.Data) {
delta = false
deltaData = fullPub.Data
}
if key.ProtocolType == protocol.TypeJSON {
deltaPub = &protocol.Publication{
Offset: fullPub.Offset,
Data: json.Escape(convert.BytesToString(patch)),
Info: fullPub.Info,
Tags: fullPub.Tags,
Delta: true,
}
} else {
deltaPub = &protocol.Publication{
Offset: fullPub.Offset,
Data: patch,
Info: fullPub.Info,
Tags: fullPub.Tags,
Delta: true,
}
deltaData = json.Escape(convert.BytesToString(deltaData))
}
deltaPub = &protocol.Publication{
Offset: fullPub.Offset,
Data: deltaData,
Info: fullPub.Info,
Tags: fullPub.Tags,
Delta: delta,
}
} else if prevPub == nil && key.ProtocolType == protocol.TypeJSON && key.DeltaType == DeltaTypeFossil {
// In JSON and Fossil case we need to send full state in JSON string format.
Expand Down

0 comments on commit f41c0bf

Please sign in to comment.