mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-29 02:21:44 +00:00
## About The Pull Request
Moth and I came up with an affront to god and man, and used it to track
the time spent creating /static (and in theory /global) variables (this
happens right at the start of init)
They cost as a sum about 0.05 seconds btw, at least currently.
```
/datum/timer
var/key
/datum/timer/New(file, line)
src.key = "[file]:[line]"
/datum/timer/proc/operator*(x)
rustg_time_reset(key)
return x
/datum/timer/proc/operator+(x)
var/time = rustg_time_microseconds(key)
world.log << "TIMER: [key]: [time]"
return x
Regex:
var/static/([\w/]+) =
-> var/static/$1 = (new /datum/timer(__FILE__, __LINE__)) * (new /datum/timer(__FILE__, __LINE__)) +
```
Output on moth's pc looks like this, time in microseconds
[output_sorted.csv](https://github.com/tgstation/tgstation/files/11241900/output_sorted.csv)
Most of this is either icon_states() memes (which appears to be cached
btw, that's interesting), or a variation on typecacheof()
There is one get_asset_datum call, but that is ALREADY cached and so is
just redundant. That's a good 0.01 seconds saved.
The rest of the time here is slightly more interesting.
The majority of typecacheof() is iterating the output of typesof(), a
byond internal proc that returns a list of types that either are or are
the child of the passed in type.
A decent chunk of time here (0.005 seconds, or 10% of the proc) can be
saved by unrolling the arguments to the proc.
It takes an arbitrary amount of typepaths as input, but we can't like
use arglist() here (cause this is an internal "proc"), so instead we try
a window of args, passing in null if we start to try and take in too
much.
Window size matters, zebra fits better into 4 then 5, especially because
of how grouping needs to work to make this effect happen.
We save about 0.001 for zebra btw, which is around about 7%. It's lower
cause we need to group the paths beforehand I think.
The speedup is minor, but it DOES exist. Plus it's fun.
## Why It's Good For The Game
Microing is a hell of a drug