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,6 +14,9 @@ init -1000 python early:
def get_renderer():
return "DirectX" if preferences.renderer == "angle2" else "OpenGL"
if config.developer:
# Debug
def detect_orphaned_rpyc_files():
excluded = ["tl/"]

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