return { id:self.id, username:self.username, score:self.score, level:self.level };
vs
return {id:self.id,username:self.username score:self.score,level:self.level};
Is there any size difference between 0/1 and true/false for Json?
Is there a size difference between "11" (string) and 11 (double)?
The Json will be sent 10 times every second with socket.emit of Socket.io.
"mybool:true,mynumber:1"
So, if you were to optomize for size "a:true,b:1"` note the NAME is smaller so the serialzed content would be."mysuperlongnameisgreat:"11",mysuperlongnumbername:11"
vs {"a":"11","b":11}"
thus the number is smaller by excluding those two quotes.All that being said considering the total processing (IF speed is an issue) this has to be deserialized into a JavaScript object on the client side so IF you are using the number as a number it will need to parse that at some point to the proper type and thus may be more of an impact than serialized content size.
Note that with short names, you WILL have a negative impact on maintenance as it is much less intuitive to maintain short non-descriptive names than longer ones.
Using your example, it would be "smaller" to do (assuming a strongly typed server side)
return {
d:self.id,
n:self.username,
s:self.score,
v:self.level
};