Amortize the cost of creating preference assets by caching them per git revision on production, reducing best case init times by ~20 seconds (#63503)

Preference asset creation, which while consistently created in early assets, can be requested at any time before then and often is, currently takes about 15 to 25 seconds to produce. Because of extremely hard to reproduce BYOND icon bugs, most of this is done on the same tick.

Lowering the cost of initialization itself is very tricky. Some of it we can theoretically optimize, such as creating humans for antagonists, others we can't, such as the raw cost of icon blending.

Furthermore, adding new icons later down the line would just increase this initialization time even more.

Instead of optimizing the asset creation, which is an uphill battle, this instead chooses to amortize the cost by caching preference assets created per git revision. This means that preference assets will be created, with their long delay, only once whenever the code changes.

This is done on a config, defaulting to on so that production needs no changes, as the whole point of these being made at runtime at all is that it keeps assets/art styles consistent, and PRs making subtle bugs that break preference generation in some way is not uncommon. On development, your git revision will stay the same until you commit, no matter what code changes you make.
This commit is contained in:
Mothblocks
2022-01-01 04:36:30 +00:00
committed by GitHub
parent d4b3462362
commit af8902331d
8 changed files with 134 additions and 37 deletions
+2 -3
View File
@@ -2,8 +2,9 @@
/datum/asset/spritesheet/preferences
name = "preferences"
early = TRUE
cross_round_cachable = TRUE
/datum/asset/spritesheet/preferences/register()
/datum/asset/spritesheet/preferences/create_spritesheets()
var/list/to_insert = list()
for (var/preference_key in GLOB.preference_entries_by_key)
@@ -36,8 +37,6 @@
var/list/inserting = to_insert[spritesheet_key]
Insert(spritesheet_key, inserting[1], inserting[2])
return ..()
/// Returns the key that will be used in the spritesheet for a given value.
/datum/preference/proc/get_spritesheet_key(value)
return "[savefile_key]___[sanitize_css_class_name(value)]"
@@ -108,8 +108,9 @@
/datum/asset/spritesheet/antagonists
name = "antagonists"
early = TRUE
cross_round_cachable = TRUE
/datum/asset/spritesheet/antagonists/register()
/datum/asset/spritesheet/antagonists/create_spritesheets()
// Antagonists that don't have a dynamic ruleset, but do have a preference
var/static/list/non_ruleset_antagonists = list(
ROLE_FUGITIVE = /datum/antagonist/fugitive,
@@ -156,8 +157,6 @@
for (var/spritesheet_key in to_insert)
Insert(spritesheet_key, to_insert[spritesheet_key])
return ..()
/// Serializes an antag name to be used for preferences UI
/proc/serialize_antag_name(antag_name)
// These are sent through CSS, so they need to be safe to use as class names.
@@ -9,8 +9,9 @@
/datum/asset/spritesheet/species
name = "species"
early = TRUE
cross_round_cachable = TRUE
/datum/asset/spritesheet/species/register()
/datum/asset/spritesheet/species/create_spritesheets()
var/list/to_insert = list()
for (var/species_id in get_selectable_species())
@@ -32,5 +33,3 @@
for (var/spritesheet_key in to_insert)
Insert(spritesheet_key, to_insert[spritesheet_key])
return ..()