I am making a jQuery autocomplete and I have something between 10~20k registers.
The data is static (i'll run a update script when i need) and I can choose to get the file from a JSON or embed in the page in a single line like:
var title = ["example title 1","example title 2"];
Which one should I choose performance wise? (also I am worried about crashing/lagging peoples browser).. And what about XML?
BTW my PHP script is already using a cache system for the HTML.
IF you're searching for a value then JSON can have better performance because it's a hashmap implementation, so the lookup time would be O(1). JSON is also more flexible, since you can have arrays in your JSON, you can have named keys, etc.
Not exactly. JSON is a data format that is independent of any programming language, although it is derived from JavaScript. The bulk of modern programming languages contain code that can generate and parse JSON data.
The short version: Arrays are mostly faster than objects.
Objects will be used when we need fast access, insertion and removal of an element as objects are comparatively much faster than the arrays in case of insertion and removal.
You should consider using JSON over AJAX to fetch the data. It will make your page seem like it loads a lot faster. You can then use WebWorkers (if the system supports them) to parse the JSON data in a separate thread. This would be idea.
500kb of JSON likely would not cause any significantly significant parsing overhead, so I wouldn't worry about crashing anyone's browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With