3

Forewarning: a potentially silly question, purely out of curiosity.

If, for example, I perform an AJAX request and get back an array of 1,000 objects like this;

{
    MinimumDistance: ...,
    MaximumDistance: ...,
    MinimumTime: ...,
    MaximumTime: ...,
    ReallyLongButDescriptivePropertyName: ...
} 

Will this consume more memory than if I had shorten the member names (e.g. MinDist)?

If so, is there anything I do to lessen the memory footprint of these objects rather than shortening the member names?

Thanks.

Barg
  • 2,968
  • 7
  • 26
  • 28
  • Request fewer objects (by using pagination). – Matthias Mar 15 '12 at 12:31
  • You could combine some of the keys... instead of Min/Max you could have `DistanceRange: [min, max], TimeRange: [min, max]` for example. – mVChr Mar 15 '12 at 12:32
  • Given that you can access the members by their names, the names must therefore be stored in memory and so reducing them would save you a trivial amount of memory. (deflate/gzip would reduce the transmission size) – Alex K. Mar 15 '12 at 12:32
  • 2
    rel: http://stackoverflow.com/questions/5276915/do-common-javascript-implementations-use-string-interning – georg Mar 15 '12 at 12:34
  • Thanks for that, thg435 - I think that answers my question! – Barg Mar 15 '12 at 12:38

1 Answers1

0

Using longer properties might end up in a longer ( meaning that it occupies more bytes and so more bandwith and more time to reach the client) response. But usually the response is gzipped and so the overhead is minimal compared to the usefulness of having understandable property names.
In any case returning 1.000 object is not a good practice, you should page them and keep your response as small as possible, particularly considering that mobile phones have reduced bandwidth

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
  • Thanks, but I'm more wondering about the overhead once the objects are decompressed and stored in memory. – Barg Mar 15 '12 at 12:36
  • @Barg that's trivial i think even if your object occupies 5 megabytes of memory (and that's a lot of text) the memory footprint would be very low. The real problem would be the overhead of iterating over big collections, in my opinion – Nicola Peluchetti Mar 15 '12 at 12:39