Skip to content

Commit

Permalink
Startup optimization - 218 seconds -> 154.7 (sojourn-13#5524)
Browse files Browse the repository at this point in the history
* Update byond-tracy to support 1641

* Replace if(x in vars) with try/catch, take 44 seconds off init

* Reduce SSmapping cost by 6 seconds by getting rid of a stupid ass way to set up teleport locs

* Reduce wall init time by 3.5 seconds

* Only take weakrefs when needed in transforms - 8.1 seconds
  • Loading branch information
ShadowLarkens authored Jul 8, 2024
1 parent a9a6468 commit 6979c64
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 47 deletions.
6 changes: 6 additions & 0 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,9 @@
/// BYOND's string procs don't support being used on datum references (as in it doesn't look for a name for stringification)
/// We just use this macro to ensure that we will only pass strings to this BYOND-level function without developers needing to really worry about it.
#define LOWER_TEXT(thing) lowertext(UNLINT("[thing]"))

/**
* \ref behaviour got changed in 512 so this is necesary to replicate old behaviour.
* This is the more performant version, it is unfortunately necessary.
**/
#define REF(thing) (thing && isdatum(thing) && (thing:datum_flags & DF_USE_TAG) && thing:tag ? "[thing:tag]" : "\ref[thing]")
4 changes: 2 additions & 2 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
if(isdatum(key))
new_key = "[key] [REF(key)]"
else if(key == world)
new_key = "world [REF(world)]"
new_key = "world \ref[world]"
else if(islist(key))
new_key = refify_list(key)
var/value
Expand All @@ -823,7 +823,7 @@
if(isdatum(value))
value = "[value] [REF(value)]"
else if(value == world)
value = "world [REF(world)]"
value = "world \ref[world]"
else if(islist(value))
value = refify_list(value)
var/list/to_add = list(new_key)
Expand Down
11 changes: 10 additions & 1 deletion code/__HELPERS/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@

return contents


/proc/pick_area_turf(var/areatype, var/list/predicates)
var/list/turfs = get_area_turfs(areatype, predicates)
if(turfs && turfs.len)
return pick(turfs)

// Used by SSmapping
// We just need to find a single turf that's on the station level
/proc/area_has_station_turf(area/A)
for(var/turf/T in A.contents) // cursed world iteration
if(isStationLevel(T.z))
return TRUE
return FALSE



/proc/is_matching_vessel(var/atom/A, var/atom/B)
var/area/area1 = get_area(A)
var/area/area2 = get_area(B)
Expand Down
16 changes: 0 additions & 16 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1382,22 +1382,6 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)
/proc/pass(...)
return

/**
* \ref behaviour got changed in 512 so this is necesary to replicate old behaviour.
* If it ever becomes necesary to get a more performant REF(), this lies here in wait
* #define REF(thing) (thing && isdatum(thing) && (thing:datum_flags & DF_USE_TAG) && thing:tag ? "[thing:tag]" : "\ref[thing]")
**/
/proc/REF(input)
if(isdatum(input))
var/datum/thing = input
if(thing.datum_flags & DF_USE_TAG)
if(!thing.tag)
stack_trace("A ref was requested of an object with DF_USE_TAG set but no tag: [thing]")
thing.datum_flags &= ~DF_USE_TAG
else
return "\[[url_encode(thing.tag)]\]"
return "\ref[input]"

// Makes a call in the context of a different usr
// Use sparingly
/world/proc/PushUsr(mob/M, datum/callback/CB, ...)
Expand Down
32 changes: 10 additions & 22 deletions code/controllers/subsystems/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,19 @@ SUBSYSTEM_DEF(mapping)
for(var/area/A in world)
GLOB.map_areas += A

// Do the same for teleport locs
for(var/area/AR in world)
if(istype(AR, /area/shuttle) || istype(AR, /area/wizard_station)) continue
if(teleportlocs.Find(AR.name)) continue
var/turf/picked = pick_area_turf(AR.type, list(/proc/is_station_turf))
if (picked)
teleportlocs += AR.name
teleportlocs[AR.name] = AR
if(!teleportlocs.Find("[A.name]") && !istype(A, /area/shuttle) && !istype(A, /area/wizard_station))
if(area_has_station_turf(A))
teleportlocs["[A.name]"] = A

teleportlocs = sortAssoc(teleportlocs)
if(!ghostteleportlocs.Find("[A.name]"))
if(istype(A, /area/turret_protected/aisat) || istype(A, /area/derelict) || istype(A, /area/shuttle/specops/centcom))
ghostteleportlocs["[A.name]"] = A
else if(area_has_station_turf(A))
ghostteleportlocs["[A.name]"] = A

// And the same for ghost teleport locs
teleportlocs = sortList(teleportlocs)
ghostteleportlocs = sortList(ghostteleportlocs)


for(var/area/AR in world)
if(ghostteleportlocs.Find(AR.name)) continue
if(istype(AR, /area/turret_protected/aisat) || istype(AR, /area/derelict) || istype(AR, /area/shuttle/specops/centcom))
ghostteleportlocs += AR.name
ghostteleportlocs[AR.name] = AR
var/turf/picked = pick_area_turf(AR.type, list(/proc/is_station_turf))
if (picked)
ghostteleportlocs += AR.name
ghostteleportlocs[AR.name] = AR

ghostteleportlocs = sortAssoc(ghostteleportlocs)
return ..()

/datum/controller/subsystem/mapping/proc/build_overmap()
Expand Down
5 changes: 4 additions & 1 deletion code/datums/transformation_types/transform_types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
var/override = FALSE
/// The atom we are applied to.
var/atom/holder
/// If you actually use value_target, set this to TRUE. Weakrefs aren't free.
var/needs_value_target = FALSE
/// The atom we use for updating our values and such. Weakreffed, as we have no way of ensuring it isn't being deleted.
var/datum/weakref/value_target

Expand Down Expand Up @@ -348,5 +350,6 @@

/datum/transform_type/proc/update_holder_status(to_be_held_by, to_use_for_values)
holder = to_be_held_by
value_target = WEAKREF(to_use_for_values)
if(needs_value_target)
value_target = WEAKREF(to_use_for_values)

3 changes: 3 additions & 0 deletions code/datums/transformation_types/types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
/datum/transform_type/ameridian_structures/crystal_resizing
flag = AMERIDIAN_CRYSTAL_RESIZING_TRANSFORM
priority = AMERIDIAN_CRYSTAL_RESIZING_TRANSFORM_PRIORITY
needs_value_target = TRUE

/datum/transform_type/ameridian_structures/crystal_resizing/update_values()
. = ..()
Expand All @@ -82,6 +83,7 @@
/datum/transform_type/shard/variable_size
flag = SHARD_VARIABLE_SIZE_TRANSFORM
priority = SHARD_VARIABLE_SIZE_TRANSFORM_PRIORITY
needs_value_target = TRUE

/datum/transform_type/shard/variable_size/update_values()

Expand All @@ -105,6 +107,7 @@
/datum/transform_type/human/size_scaling
flag = HUMAN_SIZE_SCALING_TRANSFORM
priority = HUMAN_SIZE_SCALING_TRANSFORM_PRIORITY
needs_value_target = TRUE

//I'm not sure if this obsolete or not. Size transofrmations should be handled now in update_icons.dm --Evie
/datum/transform_type/human/size_scaling/update_values()
Expand Down
4 changes: 2 additions & 2 deletions code/game/turfs/simulated/wall_icon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
update_material()

/turf/simulated/wall/update_icon()
var/static/all_wall_states = json_decode(rustg_dmi_icon_states("icons/turf/wall_masks.dmi"))
if(!icon_base)
return

cut_overlays()
var/image/I
for(var/i = 1 to 4)
I = image('icons/turf/wall_masks.dmi', "[icon_base][wall_connections[i]]", dir = GLOB.cardinal[i])

I.color = base_color
add_overlay(I)

Expand All @@ -87,7 +87,7 @@
I.color = reinf_color
add_overlay(I)
else
if("[icon_base_reinf]0" in icon_states('icons/turf/wall_masks.dmi'))
if("[icon_base_reinf]0" in all_wall_states)
// Directional icon
for(var/i = 1 to 4)
I = image('icons/turf/wall_masks.dmi', "[icon_base_reinf][wall_connections[i]]", dir = 1<<(i-1))
Expand Down
11 changes: 8 additions & 3 deletions code/modules/projectiles/gun_firemode.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
gun = _gun

for(var/propname in settings)
if(propname in gun.vars)
if(propname == "damage_mult_add")
gun.damage_multiplier += settings[propname]
continue

try
gun.vars[propname] = settings[propname]

// Apply gunmods effects that have been erased by the previous line
Expand All @@ -71,8 +75,9 @@
var/datum/component/item_upgrade/IU = I.GetComponent(/datum/component/item_upgrade)
if(IU.weapon_upgrades[GUN_UPGRADE_FIRE_DELAY_MULT])
gun.vars["fire_delay"] *= IU.weapon_upgrades[GUN_UPGRADE_FIRE_DELAY_MULT]
else if(propname == "damage_mult_add")
gun.damage_multiplier += settings[propname]
catch
// throw away exception, we don't care
continue



Expand Down
Binary file modified prof.dll
Binary file not shown.

0 comments on commit 6979c64

Please sign in to comment.