Unity profiler, Update.ScriptRunDelayedTask causes spikes - c#

I'm having some spikes problems in my mobile game and I think the problem is caused by the Update.ScriptRunDelayedTask, but I don't understand what it means speicifically. It means coroutines? Delay on the monobehaviour made by IEnumerator like "IEnumerator Start()" or maybe async functions that cause delay? Can you help me understand where to search? here's a screenshot of the profiler

Related

Unity's Universal Render Pipeline performance problem? (2D)

I never got real answer for this. I open this new empty project (total blank but with one GameObject)
I ended up getting 2500FPS, alright? Makes sense. The moment I install URP and then you know place in the graphics asset. BAM 1100FPS. What's going on? I put lights, well FPS keeps on decreasing. Wasn't this supposed to be better than the normal standard pipeline? If I can't do this, what are the other ways to make these optimized lights? What can I do for it?
P.S. I have been using since LWRP and then recently changed to URP. It's been at least a year, I feel like I cannot make my own game using these lights and I don't know what to do with it. This is the performance loss after just installing it, think when you have to add logic? Well, that is bad. Do I look for certain settings for this?
If your game is running above 60FPS you are OK. you do not have to worry about performance at this stage. Add assets according to your game design, tweak your scene with lights, Unity offers my tools than can improve the performance of the game. But I suggest you do profiling after you build something concrete.
You shouldn't really look at frame-rate for profiling, you need to look at the time per frame not the FPS count. Remember that the FPS is logarithmic, not linear. 2,500 FPS is a frame render of 0.4ms where 1,100 FPS is 0.9ms. The difference in this time is so small that it's almost not worth comparing. Also, target should be 60 - 144 FPS (depending on screen refresh-rate) which is a frame-time of 16.67ms - 6.9ms.
Also you need to remember that URP is forward-rendered which means the cost of each light in the scene goes up dramatically vs in Deferred in Standard.

getting really bad prefomace issue in unity when trying to move more then 1000 rigidbodies in the scene

I have an object build from aprox. 1700 small cube meshes (pretty simple ones). if there are been hit i'm trying to return it to the origin a few seconds after any other objects hits it (the trigger is any other collision).
the result is between very poor performance to complety stuck.
what i tried to do so far :
limit the object to one collision trigger to avoid activation over and over again .
disable the object physics
move the object using both Physics and the transform directly.
what seems to be the problem ? can unity even handle that much objects and collisions ?
Screenshots of profiler will make easier to think a proper solution for this situation i think. I don't think any draw calls or collisions cause this problem. More about Unity3D profiler is here. You can try to handle physics in Fixed update and try different combinations of rigidbody attributes (Interpolate etc.). Goodluck.
The problem is that Physics in Unity is not a native solution. Unity uses PhysX for physics, and but of them are used like a black box so Unity doesn't know how it works under the hood. That's why all physics-based operations are complex and have rather bad performance. 1000 physics-based objects seems to much to handle by Unity3d. And it's not the only limit in Unity, for example if you create about 10 000 gameobjects (no matter which functionality they will have) they can freeze even Unity's editor.
As for a possible solution there's not much you can do:
Look through optimization guides and best practises here, here and here.
Use Unity's profiler to optimize Physics performance (try to remove physics-based "spikes")
Try to develop some system which will disable gameobject's which are not seen on scene in current moment.
Try to simplify the meshes and collider. Or try to make 1 big mesh which will split into smaller parts when you need interaction.
Try to create your own simple mathematically-based physic. I know it will be really complicated but your not universal physical solutions may have much better performance rather than PhysX.
So anyway it will be a difficult struggle.

Extremely high CPU load in render loop

I am still working on my video game and my own game engine and I make a good progress. This weekend, I wanted to take some time to improve the performance of my game and to check for any memory leaks and so on. While most things look fine, I have an incredible high CPU load of around 45% (on an Intel i5 with four cores). First, I thought I had some very bad design in one of my modules, but even after removing all parts from the render process I still had a CPU load of around 40%!
This was my render loop after removing all my modules' render calls:
public void Run()
{
_logger.BeginFunction(this.ToString(), "Run");
RenderLoop.Run(Form, () =>
{
_deviceContext.ClearDepthStencilView(_depthView, SharpDX.Direct3D11.DepthStencilClearFlags.Depth, 1.0f, 0);
_deviceContext.ClearRenderTargetView(_renderTargetView, Color.Black);
_swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
});
OnApplicationClosing();
_logger.EndFunction();
}
So, as you can see almost nothing happens and I still got that 40% CPU load. I checked, if anything is running in the background by printing the current stack trace every 5 seconds. Nothing was running in this process, after I disabled all my game engine's modules.
Then I remembered I had a similar issue many years ago during my studies, when a calculation thread was in an endless loop. Since the loop was not slowed down, it was executed as fast as possible which caused a high CPU load. Remembering this, I added an ugly line at the end of my render loop above:
System.Threading.Thread.Sleep(10);
Et voilĂ , my CPU load goes down to around 10%, even with all my game engine's modules activated.
However, this is not an acceptable final solution for my game engine. I took some time looking online for SharpDX render loop examples, but I was not able to figure out how other people handle this problem.
Is there any way to avoid the high CPU load without slowing the render loop down with a thread sleep?
I'd appreciate any hints and help from you! :-)
Simply replace:
_swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
by
_swapChain.Present(1, SharpDX.DXGI.PresentFlags.None);
As stated in MSDN Swapchain:Present doc:
0 - The presentation occurs immediately, there is no synchronization.
1 through 4 - Synchronize presentation after the nth vertical blank.

c# 80% Cpu at once. Can't find where the bug is / (on a game server with 250 online)

Hello I made a game server in c# for a big online game.
The only problem is that I get sometimes out of no where 90% cpu usage.
It also got stuck on that 90% when the bug is there it stays on the 90% for ever..
So my question is how can I find the code failure on a simple way because the server is huge.
Are there any .net profilers good foor or something like that?
It also got stuck on that 90% when the bug is there it stays on the 90% for ever
That's awesome! You just got handed the holy grail right there my friend!
Simply attach a debugger when it gets in that state and break. Chances are you'll break in the buggy code, if not keep running and breaking. You should get there really quick if it's using 90% of your CPU.
Alternatively run it through VS's profiler and zoom the graph in only the zone with extremely high sustained CPU usage, you'll get a list of functions that use the most time (assuming it's a CPU bound issue, if it's I/O I don't think it will show).

Game Jitters on xBox360

Ok i've got my game nearing completion, everything is working perfectly in it and it runs fairly well on my computer (running at around 99Mb RAM). But when i run it on my xBox, i tend to get occasional jitters of the main player character. I do have explosions and billboard effects inside my game however i'm doing all that rendering on the xBox GPU (that was originally causing the jitters when explosions occurred, but not anymore).
The jitters are random as well, not when i'm spawning large amounts of units, or performing lots of actions. I'm at a loss as to why this is happening, any ideas??
P.s. The game does have multi-threading integrated into it, update on one thread, rendering on another thread.
It sounds like the garbage collector is causing your jitters. On Xbox it kicks in every time 1MB of data is allocated. The amount of time it takes depends on how many references are in use in your program.
Use the XNA Framework Remote Performance Monitor for Xbox 360 to tell if you have a garbage collection problem. Read How to tell if your garbage collection is too slow by Shawn Hargreaves.
If you do have a garbage collection problem, you'll need a profiler that can determine which objects are generating the garbage. The CLR Profiler for the .NET Framework 2.0 is one option. It's not supported in XNA 4.0 by default, but Dave on Crappy Coding has a workaround. For strategies to solve your garbage collection problem read Twin paths to garbage collection Nirvana by Shawn Hargreaves.
Update: The CLR Profiler for the .NET Framework 4.0 is now available.
Sounds like your rendering thread is just sat there waiting for the update thread to finish what its doing which causes the "jitter". Perhaps put in some code that logs how long a thread has to wait for before being allowed access to the other thread to find out if this really is the issue.

Categories

Resources