tgstation / dev-cycles-initiative

Hub for tracking issues in the Dev Cycles Initiative
1 stars 0 forks source link

Setting limbs seems to force an icon regeneration every time, twice, leading to creation of (mostly) monkeys being extremely expensive #18

Closed Mothblocks closed 1 year ago

Mothblocks commented 1 year ago

species/proc/on_species_gain is 358ms over 26 calls (config'd, more without because of prefs menu). Median time per call is 13.8ms.

The cost of this is 80% from species/proc/replace_body, and 19% from species/proc/regenerate_organs.

74% of species/proc/replace_body is /obj/item/bodypart/proc/replace_limb (182ms over 156 calls). Of this, 53% is try_attach_limb, 46% is drop_limb.

The cost for both eventually ends up being mostly in carbon/update_body -> carbon/proc/update_body_parts -> getting icons, updating overlays, removing overlays, etc etc etc. It's an enormous waste of processing power.

Savings amount (.182) is based off of replace_limb.

Mothblocks commented 1 year ago

I think some of this came from removing overlay queueing.

CC @Kapu1178.

Mothblocks commented 1 year ago

Also, ideally the /species subtypes of human shouldn't be creating a human with human limbs updating with human limb code on initialize. species/Initialize is 326ms over 5 calls, and most of that is just wasted work.

Kapu1178 commented 1 year ago

maybe the cache broke at some point, as limb icons are cached. Well, the icons that are applied during update_body_parts().

Kapu1178 commented 1 year ago

i looked into this for 2 seconds, only because if the cache is broken that'd piss me off.

its not broken, its just species retardation.

because monkeys spawn with randomized dna, it needs to first draw and cache the human bodyparts. Because you can't spawn as a species, you spawn as a human and get set_species()'d into it. This is most impacted by skintones, as if that skintone hasn't been generated prior in the round, it will have to generate each limb for the skin tone. And due to the nature of heads, every monkey is a new head icon, because heads have so many variables its unlikely for the same one to generate twice during mob spawning.

Mothblocks commented 1 year ago

My last post still has relevance then, /species should avoid doing all of that until we know it's necessary (which it wouldn't be for monkeys, but would be for felinids)

Kapu1178 commented 1 year ago

Good luck doing that while maintaining what little readability exists of species and bodypart code, and without introducing new footguns.

Mothblocks commented 1 year ago

My last post still has relevance then, /species should avoid doing all of that until we know it's necessary (which it wouldn't be for monkeys, but would be for felinids)

Done