- Jan 19, 2020
- 12,382
- 48,852
anne O'nymous: Mentor, I need some advice. Rather than a PM I thought others might benefit from a brief discussion if you wouldn't mind.
Problem/Issue:
For over a year I've been battling the creation of a very large dictionary which if I don't keep in restraint can significantly increase game load times and just not efficient due to how expensive it is to create large dicts. For others that might see this thread know that yes, I've worked with different variants of creating the dictionaries to minimize the timeframe but the resulting difference is minimal at best. For example, I've used the following with nearly identical results:
The low down: The dictionary in question consists of tupled lists to serve as keys against another dictionary of string items (that's significantly smaller so no worries there) and all used in another function who's purpose is not relevant to the topic... just know it's required and I'm not insane...maybe. AON actually helped me create the beast but it's grown into a monster over the last year or so. Enough yammering... onward.
Current similar code that creates the dict as normal (in memory at initialization). This creates a sorting that's similar to using
Current possible solution that creates the dict and dumps to a txt file and once it's done, on subsequent game starts, the required dict info is simply read from the file rather than recreating it in memory again thus eliminating the startup time expense. This works but not yet implemented... am I nuts for going down this path?:
Example "myKeys" output if file doesn't exist (from print):
Example "myKeys" input if file does exist (from print):
I've never done this before in Python much less incorporated into RenPy so would appreciate your thoughts. This seems feasible as subsequent game starts don't have to spend the expense of rebuilding the massive dictionary each time. You've told be before if it works then it works but I'm just making sure I've not started thinking a little too far outside the box. Your insight is always appreciated.
Regards and hope all has been well with you and yours.
Problem/Issue:
For over a year I've been battling the creation of a very large dictionary which if I don't keep in restraint can significantly increase game load times and just not efficient due to how expensive it is to create large dicts. For others that might see this thread know that yes, I've worked with different variants of creating the dictionaries to minimize the timeframe but the resulting difference is minimal at best. For example, I've used the following with nearly identical results:
{k: k for k in it}
dict.fromkeys(it)
dict(zip(it, it))
- etc.
I'm now not sure if I'm wasting my time or on to something just very slightly brilliant?
The low down: The dictionary in question consists of tupled lists to serve as keys against another dictionary of string items (that's significantly smaller so no worries there) and all used in another function who's purpose is not relevant to the topic... just know it's required and I'm not insane...maybe. AON actually helped me create the beast but it's grown into a monster over the last year or so. Enough yammering... onward.
Current similar code that creates the dict as normal (in memory at initialization). This creates a sorting that's similar to using
itertools.combinations
generator in succession:You don't have permission to view the spoiler content.
Log in or register now.
Current possible solution that creates the dict and dumps to a txt file and once it's done, on subsequent game starts, the required dict info is simply read from the file rather than recreating it in memory again thus eliminating the startup time expense. This works but not yet implemented... am I nuts for going down this path?:
You don't have permission to view the spoiler content.
Log in or register now.
Example "myKeys" output if file doesn't exist (from print):
You don't have permission to view the spoiler content.
Log in or register now.
You don't have permission to view the spoiler content.
Log in or register now.
I've never done this before in Python much less incorporated into RenPy so would appreciate your thoughts. This seems feasible as subsequent game starts don't have to spend the expense of rebuilding the massive dictionary each time. You've told be before if it works then it works but I'm just making sure I've not started thinking a little too far outside the box. Your insight is always appreciated.
Regards and hope all has been well with you and yours.