Hi All:
We've got the following code sample:
big_static_data = {
"key1" : {
"subkey1" : "subvalue1",
...
},
"key2" :
...
}
class StaticDataEarlyLoad:
def __init__(self):
self.static_data = big_static_data
# other init
def handle_use_id(self, id):
return complex_handle(self.static_data, id)
...
class StaticDataLazyLoad:
def __init__(self):
# not init static data
# other init
def handle_use_id(self, id):
return complex_handle(big_static_data, id)
...
Just as the above codes say, whenever we call the instance's *handle_use_id*, we may get different performance issues.
IMO, early load will load the data when the instance is created, and will be in memory till the instance is garbaged. And for late load, the static data won't be loaded till we call the *handle_use_id* method. Am I right? (Since I'm not so clear with Python's internal, I'm not sure how long the instance will last till garbaged). And If I'm right, the early load means a big memory requirement and the late load means we have to load the data each time when invoking the method( a big overhead?)
Now, we are a web based project, So which should be selected as the best approach? (*handle_use_id* will be invoked very frequently.)
Thanks.