I'm testing some custom data formats to send between my server and the client's browser. I want to make sure that my data is as small as I thought it was, so I did some tests and was pretty confused by the results.
var bufArr = new ArrayBuffer(160000000);
var bufView = new Float64Array(bufArr);
for(i=0; i<20000000; i++) {
bufView[i] = 5.632 + i
}
On the server I make an ArrayBuffer with 160,000,000 bytes. Then I fill the buffer with an "array" of 20,000,000 float64s. each float64 is 8 bytes, so 20,000,000 * 8 = 160,000,000. at least, I think that's how this works, but please correct me if my asumption is wrong.
Next, I connect to my webpage, and when I click a button, the server uses Socket.io to send me bufArr, which simply looks like this:
socket.on('test1', function(data) {
socket.emit("test2", bufArr)
})
So in theory I should be sending about 160MB. But what I found is that it is only sending about 23MB. The client actually gets the full data, and I console log it, and look through it, and it is accurate. For example:
19989996:19990001.632
19989997:19990002.632
19989998:19990003.632
19989999:19990004.632
The number on the left is the index, so if i= 19989999, then we add 5.632 and get 19990004.6, and this is true for every index, so no data got lost or anything.
So I receive exactly 20,000,000 floating point numbers which should be 160MB, but when I check my network monitoring tools (Windows 10 settings, Task manager, and also my router traffic analysis page) and all of them say that I received about 23MB.
Is my understanding of ArrayBuffers and Float64Arrays incorrect, or is there some magic happening within socketio, or my router that is making the transmit size significantly lower?