3 ms·
>JSON is a text format and interning it into proper data structures is likely going to take _less_ space, not more. Wanna bet? >>> import sys >>> import j
by coldtea 4y ago
>JSON is a text format and interning it into proper data structures is likely going to take _less_ space, not more.
Wanna bet?
>>> import sys
>>> import json
>>> data_as_json_string = '{"a": 5000, "b": 1000}'
>>> len(data_as_json_string)
22
>>> data_as_native_structure = json.loads(data_as_json_string)
>>> sys.getsizeof(data_as_native_structure)
232
That's not even the whole story, as what's 232 bytes is not the contents of the dict, but just the Python object with the dict metadata. So the total for the struct inside is much bigger than 232 bytes.
A single int wrapped as a Python object can be quite a lot by itself:
>>> sys.getsizeof(1)
28
A binary int64 would be 8 bytes for comparison.
- berkle4455 4y agoMaybe 2023 is the year people stop using python.
- IshKebab 4y agoWe can dream but I seriously doubt it. Not only are there very few nice alternatives (Dart is great but unpopular; Typescript is great but has a terrible standard library, etc.) but very few of them have a decent REPL which I think is probably Python's most underrated feature. I mean... it's REPL is extremely basic, but anything you can do in Python you can do in the REPL. Very useful especially for beginners.
- killingtime74 4y agoPython is my favorite language but you literally chose one of the least efficient. This would probably be different in Java or Rust.
- bufferoverflow 4y agoI thought Java stores strings as 16-bit character arrays internally. Which means it's very inefficient when it comes to memory consumption.
- samus 4y agoSince version 9, Java uses ISO-8859 when possible. Most raw JSON should therefore take up very little space.
- hsn915 4y agoI'm pretty sure the GP intended the statement to be for statically typed languages with a struct-like type.
- coldtea 4y agoIt doesn't get much better there: https://news.ycombinator.com/item?id=35216761 https://news.ycombinator.com/item?id=35216761