I am not sure how replit database is implemented. I use the database to store a large python dictionary. Will the code run faster if I create a deep copy of the dictionary before using it and save it back to the db when I am finished, or is it as fast to work directly on the dictionary object returned by the call the db?
my_dict= copy.deepcopy( db["my_dict"])
db["my_dict"] = my_dict
from replit import db
my_dict = json.loads(db.get_raw("key"))
So you suggest that working on a deep copy is better and that the best way to make a deep copy is the code you propose, correct?
Um no, this gets the raw json of it and then interprets it via the
Yes, that creates a copy of the dictionary instead of a reference to an observed dictionary. That means that the copy needs to be saved back to the db otherwise, any change would be lost. If, instead, I worked directly on the object produced by the call to db, there is no need to save the dictionary back to the db but there is a lot of overhead.
Technically? It creates a string actually that is revealed to a dict
Do you know that the underlying implementation of the observed dictionary returned by the call to db . Is the observed dictionary a wrapper around a JSON string that is updated and restored every time the object is modified?