mercredi 3 janvier 2018

Does data load faster from an object's property or from json?

I am wondering if there's any performance difference at all between initializing a class from json or from an object.

So, imagine the following scenario:

func getDataFromServer(){

    ...

    var data = doc.data()
    let obj = Object(id: String, prices: [data["price"] as! Double], .. , .. , .. , .. , ..)

    if (dictionary[id] != nil) {
       // obj already exists. Update its info.

       var oldObj = dictionary[id]
       oldObj.updateInfoWith(price: obj.prices[0], .. , .. , .. , .. , ..) //(1)
       //behind the scenes updateInfoWith does: oldObj.prices.append(obj.prices[0])
    }
    else{
        objects.append(obj)
    }
}

At the (1) line, is there any difference in performance from getting the price from obj.prices[0] or from data["price"] as! Double? The data json tree is as huge as the number of properties of an Object class, such that an Object class gets all data contained in a data json tree. An Object has about 10 properties, being three of them arrays (prices being one of them).

Aucun commentaire:

Enregistrer un commentaire