Optimizations

* Disabled detection of orphaned scripts for non-devs
* Added cache to renpy.list_files to reduce IO overhead (~14s -> ~0.01s per 10k calls)
* Fixed wrong module call in weather.
This commit is contained in:
LoafyLemon 2023-01-03 21:27:35 +00:00
parent 43d18f0de1
commit 2c35c2d5df
3 changed files with 33 additions and 14 deletions

View File

@ -59,7 +59,7 @@ init python:
@weather.setter
def weather(self, value):
if value == "random":
value = renpy.python.random.choices(self.weather_types, weights=self.weather_weights)[0]
value = renpy.random.choices(self.weather_types, weights=self.weather_weights)[0]
if not value in self.weather_types:
raise ValueError("Unsupported weather type: '{}'".format(value))

View File

@ -14,22 +14,25 @@ init -1000 python early:
def get_renderer():
return "DirectX" if preferences.renderer == "angle2" else "OpenGL"
def detect_orphaned_rpyc_files():
excluded = ["tl/"]
if config.developer:
# Debug
files = renpy.list_files(common=True)
compiled = [x for x in files if x.endswith(".rpyc") if not any(x.startswith(i) for i in excluded)]
scripts = [x for x in files if x.endswith(".rpy")]
orphaned = []
def detect_orphaned_rpyc_files():
excluded = ["tl/"]
for i in compiled:
if not i[:-1] in scripts:
orphaned.append(i)
files = renpy.list_files(common=True)
compiled = [x for x in files if x.endswith(".rpyc") if not any(x.startswith(i) for i in excluded)]
scripts = [x for x in files if x.endswith(".rpy")]
orphaned = []
if orphaned:
raise Exception("Orphaned compiled scripts detected, please delete them before continuing:\n{}".format(orphaned))
for i in compiled:
if not i[:-1] in scripts:
orphaned.append(i)
detect_orphaned_rpyc_files()
if orphaned:
raise Exception("Orphaned compiled scripts detected, please delete them before continuing:\n{}".format(orphaned))
detect_orphaned_rpyc_files()
init python:
config.missing_image_callback = missing_image_func

View File

@ -60,7 +60,7 @@ init python:
config.statement_callbacks.append(crashdefender)
init -10 python:
init python early:
if renpy.windows:
# On windows, Renpy does not support backslashes in some of its functions,
@ -75,3 +75,19 @@ init -10 python:
return renpy.loader.loadable(filename)
renpy.loadable = _loadable
# renpy.list_files does not use cached results, let's fix that.
def _list_files(common=False, quick=True):
cache = "_list_files_common_cache" if common else "_list_files_cache"
files = getattr(renpy.store, cache, [])
if not quick or not files:
rv = [fn for dir, fn in renpy.loader.listdirfiles(common) if not fn.startswith("saves/")]
rv.sort()
setattr(renpy.store, cache, rv)
return files
renpy.list_files = _list_files