KylerAce and sure lets say Potato can you guys make the singulo not lag?

How, what and why to code in BYOND.
Post Reply
User avatar
Armhulen
Global Moderator
Joined: Thu Apr 28, 2016 4:30 pm
Byond Username: Armhulenn
Github Username: bazelart
Location: The Grand Tournament

KylerAce and sure lets say Potato can you guys make the singulo not lag?

Post by Armhulen » #674651

Any ideas on how to optimize the Singulo? Right now, if anything has happened in the round, it's laggy. And for the best experience, a singulo hits after something has happened in the round. You feel me? I'm hoping we can prioritize the Singulo's actions above others, but I don't know if that's possible
- Asked goof about fast explosions, it's not really the same case so that can't help here
Any ideas?
User avatar
TheFinalPotato
Code Maintainer
Joined: Sun Oct 13, 2019 7:58 am
Byond Username: LemonInTheDark

Re: KylerAce and sure lets say Potato can you guys make the singulo not lag?

Post by TheFinalPotato » #674678

When you say lag what do you mean? the singulo should not be causing TD, I took a hacksaw to how it scheduled work to ensure that.
You mean like the singulo is slower then it should be?
My ancestors are smiling at me, Imperials. Can you say the same?
Image
Image
Image
Image
User avatar
Kylerace
Code Maintainer
Joined: Fri Nov 29, 2019 10:32 pm
Byond Username: KylerAce

Re: KylerAce and sure lets say Potato can you guys make the singulo not lag?

Post by Kylerace » #674682

if you want to make the singulo more responsive when everything is lagging try making singuloprocess a non background subsystem (which it inherits from the parent processing subsystem) so it doesnt have to compete with atmos for the leftover cpu time. theres not really much point in singulo being background anyways since once it starts moving stuff towards it and creating active turfs its already making a bunch of work for other subsystems.

if you want to make the singulo lag the server out less:
I profiled this by spawning a singularity on upper tram and giving it a supermatter shard, then turning on the inbuilt profiler and tracy. i turned both off after the singularity left the station.

byond profiler:
singulo_test.txt
(547.71 KiB) Downloaded 22 times
tracy: <i cant upload it via the forum or discord sorry>

the first thing to know is that it creates literally thousands of active turfs, and it causes a bunch of lighting updates. Image
secondly most of the work spent in singularity/process() is spent in digest() to eat or pull everything in range, most of that is spent in singularity_pull() (83%) and some is spent in consume() (16%) to actually destroy it

singularity_pull() is overridden dozens of times, but the biggest cost eaters are items by a fair margin, turfs are a small portion. /obj/item/singularity_pull() has a total cost of 5.335 seconds over 11205 calls and /obj/singularity_pull() is 5.204 seconds but with 3x the calls at 33523, this is because items call throw_at() and offload work into the throwing subsystem, and then call parent which moves them with step_towards() which calls Move()

so essentially /datum/component/singularity/process() spends most of its time moving objects to itself either directly or by throwing which is offloading work to the throwing subsystem

subsystems the singularity stresses:
SSsinguloprocess (17.033 seconds total) via the obvious, eating turfs and movables within range and pulling those that arent towards itself. spams movement and qdeletes
SSthrowing (3.584 seconds total) via throwing items in singularity_pull(), note that this only handles thrown items that havent already been eaten by the singularity
SSair (47.444 seconds total) via creating a fuckton of active turfs and pipenet rebuilds
SSlighting (16.763 seconds total) via spamming lighting updates by breaking atoms with opacity and breaking/moving light sources

unfortunately all of these are pretty dense, i dont see an obvious big win here.
the best way to optimize it is probably to focus on singularity_pull(), it looks like items are moved twice every time theyre pulled because throw_at() moves when called by default, and it calls parent which moves it as well. might be better to just make them move once when pulled. you might even be able to just not throw at all and rely on the singularity to move them each time theyre in range, though that might look bad.
besides that pipes take a long time in Destroy(), there might be a better way to handle pipenet rebuilds
Attachments
Screenshot_2926.png
Screenshot_2926.png (6.13 KiB) Viewed 1506 times
Image
User avatar
TheFinalPotato
Code Maintainer
Joined: Sun Oct 13, 2019 7:58 am
Byond Username: LemonInTheDark

Re: KylerAce and sure lets say Potato can you guys make the singulo not lag?

Post by TheFinalPotato » #674701

LINDA my beloved
I have considered using SSwardrobe to preload things like metal sheets and rods and shit, to reduce destroy costs. Unsure of how big an impact that would make however since that's just in consume() (wait no it's not it's off pull() since we rip the station to shreds and all).
Atmos is pretty much always gonna eat shit. it'd be better with FEA groups but that's just life, and it's the bottom feeder so it's mostly ok.
Lighting is similar, anything that pulls walls down will suck.
Pipenet rebuilds should be about as good as they get, though breakaparts could in theory be queued too. In a perfect world we'd have subsections to pipelines that prevent needing to rebuild the whole net, but pipeline code needs a good chainsawing to be useful, in other ways too,

Another thing I've thought about is just like, reducing the range of the singulo a bit. it's cranked up real high rn and I get the feeling we could get similar vibes if we reduced it slightly, particularly for the sm consuming variant.
My ancestors are smiling at me, Imperials. Can you say the same?
Image
Image
Image
Image
User avatar
Armhulen
Global Moderator
Joined: Thu Apr 28, 2016 4:30 pm
Byond Username: Armhulenn
Github Username: bazelart
Location: The Grand Tournament

Re: KylerAce and sure lets say Potato can you guys make the singulo not lag?

Post by Armhulen » #674788

lol i love how i can just say kyler acce and potato in the thread title and there they go they're figuring it out

yeah so the issue is that it has to check tick so often consuming its large range around it awhile atmos and other stuff (problems IT CAUSED) slow down the game to the point where it can't even consume tiles around it, which means it also can't consume people inside it
Post Reply

Who is online

Users browsing this forum: No registered users