1

The implementation language is Javascript. I have to transmit long hexadecimal strings (actually format is not important as I can convert to any format at the transmitting end and reconvert on the receiving end) at regular interval. As these hexastrings are almost the same, it is not optimal to send them as-is. Rather I would like to send a diff.

Here is pseudo code:

 setInterval(function() {
    //Using websocket, send message to server 
    sendSomeMessage(myHexString);
 }, 10000);

Here myHexString is computed asynchronously. It may or may not change within the interval. That part is easy to optimize. I can just compare to the previous version and suppress the sending. What I need is the ability to send only diffs, when the change is actually there, as in:

 setInterval(function() {
    //Using websocket, send message to server 
    myDiff = diff(oldString, newString);
    if (myDiff.length > 0) 
        sendSomeMessage(myDiff);
 }, 10000);

At the receiving end, I will have code as in:

 newVersion = getNewVersion(oldVersion, myDiff);

I found some diff libraries in Javascript but they do just that: Display the difference. I want the ability to apply the diff result to one content and get the target content. EDIT: Would be nice to have something in Javascript which implements Linux diff and patch.

Sunny
  • 9,245
  • 10
  • 49
  • 79
  • @charlietfl That would work but even one single character insert will create a diff that would be several times the content - unless I have not understood you properly. – Sunny Apr 13 '21 at 13:16

1 Answers1

0
  1. You can reduce the amount of transmitted data by around 30% when you use base64 encoding instead of hex encoding (base16).
  2. Use a diff algorithm such as PatienceDiff to calculate which parts have changed and transmit only those that have. Take a look at this answer for more details: https://stackoverflow.com/a/57103581/13774992
ptts
  • 1,848
  • 6
  • 14
  • I am trying to reduce the bandwidth consumption. While this will work, the diff will be voluminous. I need something along the line of linux diff or more specifically vbindiff. – Sunny Apr 13 '21 at 13:43