Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of storing JSON response in Javascript

I'm working on a PhoneGap app and find it most efficient to cache as much user data as possible on the device when the user logs in. (Profile information, etc.) Due to project constraints, I can't use local storage.

I'm making an API call and pulling back of JSON data that I use to power the app. My specific question: It is somewhat safe to assume that the byte size of the JSON results will be roughly equal to the memory consumed? i.e. if the API call response is 200k of JSON data, that about 200k of memory will be used to store it in a javascript object?

like image 717
Anthony Avatar asked Nov 13 '22 04:11

Anthony


1 Answers

The best answer is, "Test it."

As several commenters have said, under many common conditions where will be a rough 1:1 correspondence, but there are so many caveats and gotchas, some of which are engine-specific, that it's impossible to say with any certainty.

In other words, if you test it and it looks like the assumption holds under your particular use-case, then 'somewhat safe' is a reasonable assumption. Just don't bet the farm on it.

like image 163
Vector Gorgoth Avatar answered Nov 14 '22 22:11

Vector Gorgoth