Noticeable if you do a loop that calls something that sleeps, and you want to make it happen simultaneously rather then one after the other, calling a lot of spawn()s adds up quickly.
Proof:
Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
---------------------------------- --------- --------- --------- ---------
/mob/proc/testwaitforspawn3 2.473 2.474 28438.984 20000
/mob/proc/testwaitfor3 2.018 2.019 29180.518 20000
/mob/proc/testwaitforspawn2 1.002 3.479 28439.971 20000
/mob/proc/testwaitfor2 0.031 2.049 29180.541 20000
/mob/verb/testwaitforspawn 0.023 0.976 0.976 1
/mob/verb/testwaitfor 0.021 2.059 2.059 1
/mob/verb/testwaitforprocoverhead 0.020 0.035 0.035 1
/mob/proc/testwaitforprocoverhead2 0.015 0.015 0.020 20000
/mob/proc/testwaitforprocoverhead3 0.000 0.002 0.003 20000
mob
verb/testwaitfor()
for (var/i = 0, i < 20000, i++)
testwaitfor2(i)
proc/testwaitfor2(i)
set waitfor=0
testwaitfor3()
proc/testwaitfor3()
sleep 1
verb/testwaitforspawn()
for (var/i = 0, i < 20000, i++)
testwaitforspawn2(i)
proc/testwaitforspawn2(i)
spawn
testwaitforspawn3()
proc/testwaitforspawn3()
sleep 1
verb/testwaitforprocoverhead()
for (var/i = 0, i < 20000, i++)
testwaitforprocoverhead2(i)
proc/testwaitforprocoverhead2(i)
testwaitforprocoverhead3()
proc/testwaitforprocoverhead3();
The reason this is faster, seems to be because it doesn't have to copy the vars to the spawn()'ed section.
Related: https://github.com/tgstation/-tg-station/pull/13443
http://web.archive.org/web/20060722121013/http:// developer.byond.com/docs/notes/225.html