Optimization Victory! (Patreon)
Content
I normally like to space out my Patreon posts by two or three days, but I felt like the post I put up yesterday deserved some closure. If you didn't get a chance to read through that post the tl;dr is that I'm hunting for the cause of the roughly minute and a half delay when starting up Lab Rats 2. After a lot of documentation, searching, and a few false starts I was starting to lose hope that I could figure out an elegent solution.
Well I have good news: I've solved the problem! After my post yesterday I found I couldn't just let the problem go and I dove into the Ren'py source code to see if I could find the cause. I had the init phase figured out and knew it would be related to image loading or indexing in some way, so I took some educated guesses and one of them paid off.
Inside of 00images.rpy there is a section of code that takes a given directory and performs some sort of pre-processing for them. Of particular note was a reference to config.images_directory, which seemed to be a list of the folders that should be searched for images that matched the pattern *.png or *.jpg (with * being the wildcard operator meaning "any word"). I had looked the documentation for the different config variables up and down a dozen times during my search and images_directory wasn't mentioned anywhere in it. By setting config.images_directory to None this preprocessing step was avoided entirely and load times were instantly and dramatically improved without any noticable impact to normal character loading!
How dramatically? While testing over the last two days I have been measuring startup times. The average was about 1:20, with some trials loading as fast as 1:05 or as slow as 1:35. Loading the game with images_directory set to None takes a grand total of 10 seconds. That's an increase in loading speed of 900%! This will be particularly nice for new players who might otherwise not bother to wait for the game to start up the first time and move on.
In the end this whole hunt took about 10 hours of dedicated work to figure out, but it was absolutely time well spent. Beyond improving the players enjoyment of the game it will almost certainly save me time in the long run! While developing new features I, as you might expect, start and restart Lab Rats 2 a lot. As a very rough estimate, if we assume I do some dev work every day and start/restart the game 5 times (some nights are much higher, others 0 or 1 start-ups) I will be saving 80*5 seconds per day, or just over 6 minutes. Every month I'm saving 3 hours and 20 minutes of work and in three months I've made back all the time I spent fixing this issue. Because it was proportional to the number of images used in the game and that was likely to only go up the time savings are even better! Of course, there's a relevant xkcd for this.
I also wanted to acknowledge some of the commenters on my previous post who had some clever ideas on how to circumvent the problem. In particular user Thanny found that the problem could be sidestepped if you changed the extensions of all of the image files (notice above how only *.png and *.jpg were looked for?). Had I not found the config option inside of the Ren'py code that likely would have been the approach I ended up taking. You guys are great!
That's all for tonight! There has been some work done on setting up character titles but that I want to talk about but it will have to wait for a future post!