Alterran / CS-PropLineTool

Cities: Skylines Mod:
http://steamcommunity.com/sharedfiles/filedetails/?id=694512541
MIT License
5 stars 3 forks source link

UIOptionPanel.Update() tanks performance #1

Open originalfoo opened 5 years ago

originalfoo commented 5 years ago

The stuff happening in the update method, and methods it calls, is absolutely tanking frame rate

https://github.com/Alterran/CS-PropLineTool/blob/master/PropLineTool_v1/UIOptionPanel.cs#L363

That's an insane amount of stuff to be doing per frame, especially the stuff in PLTToolSwitch.SwitchTools().

For example, GameObject.Find() is insanely slow and should not be used per frame.

Depending on my CPU overclocking, I get 10-15 fps drop because of that huge chunk of code being run every frame.


From vague memory, the tools have events which fire when they are activated/deactivated. You should be using those events to act upon tool state changes, not checking every frame. Using events you could probably trim the UIOptionPanel.Update() to something roughly like:

You'll notice that's an empty code panel with nothing in it.

Alterran commented 5 years ago

Hey! Thanks for looking into this with me!

With the latest update (https://github.com/Alterran/CS-PropLineTool/tree/01-05-PerformanceUpdate-01), I've reduced the calls to GameObject.Find so it is not called every frame, only when switching tools.

I cannot find events that fire when tools are activated/deactivated. Which are you referencing?

originalfoo commented 5 years ago

Can you merge that 01-05-PerformanceUpdate-01 branch with master and I'll look over it and see if I can streamline it a bit more.

I'll do some digging to find the events; currently mid way through updating my dev environment so don't have all the tools running at the moment but should have it all up and running again by tomorrow.

Alterran commented 5 years ago

Branch is now merged into master. Sweet, thank you.

Yeah if you could find the events or know how to do something similar, would be awesome!