I know this probably needs a bunch of actual tests to get an accurate answer, but I'm hoping somebody can give me a head start and potentially save me the trouble.
Let's say I've got an array of 50,000 integers, all of which are values between 0-255. I want to transfer (to and from Flash) and store that array as efficiently as possible. I'm more concerned with total speed than I am optimized data size. I do not need to store it in any kind of searchable nor human-readable form. I'm just going to chuck it in something like MongoDB and retrieve it back to Flash at some later date.
There are a few different comparisons I'm exploring:
1. If I use Remoting, is there a difference between sending an Array of integers (which gets its own automagic compression/bytearray-ing) and sending a ByteArray that's been explicitly filled with ByteArray.writeByte(x)? Would the ByteArray be smaller (and by how much?) than what the built-in AMF would make from an Array of integers?
2. If I did construct my own ByteArray to send, is it worth calling ByteArray.compress() on a bunch of integers, or is there not going to be much savings there?
3. If I did construct my own ByteArray and didn't need the data to be unserialized on the back end, is there any value in sending it via Remoting instead of just using one of the other standard HTTP methods? Whatever compressed format it's in will be unserialized by PyAMF (or any other remoting gateway) and I'd then need to serialize it again before storing, right. Seems redundant.
Just a quick follow-up on some initial local testing I've done. Sorry for posting before at least taking a few minutes to try this. It was early this morning :) .
First I made 3 calls all via Remoting and checked the size.
1- An array of 100,000 integers: 245K
2- A ByteArray of 100,000 ints: 97K
3- A ByteArray.compress() 100,000 of ints: 97K
So that answers at least one of my questions: the built-in ByteArray-ing in AMF doesn't beat an explicit ByteArray.writeByte(x). We can also see that AMF is already compressing, or there isn't any compression to be had.
But what about if x is not necessarily less than 256 but we know they're less than 65,000? Here's how the built-in AMF stacks up against ByteArray.writeShort(x).
1- An array of 100,000 integers: 365K
2- A ByteArray of 100,000 ints: 195K
So it would seem from these quick tests that AMF is just calling ByteArray.writeObject on Arrays (which makes sense) and that it doesn't try to get fancy and figure out whether the values could fit into smaller bytes.
Which finally lead me to try Vectors. Even aside from the fact that the backend gateway can't really handle them, as far as I can see from Charles, the size isn't any smaller than an Array. This part probably needs further exploration though.