How to know what to focus on for performance enhancement?
Hello all. I have delved into the (infinite) world of performance profiling as my game was having issues with frame rate dropping. I have been looking at the profiler window to try and make sense of it all but need some help to know what I should be focusing my attention on. What would be considered too slow on mobile for a script to execute? I can see the instantiates are adding around 10ms. Am I even looking in the right spot for the information on what could be slowing things down? If anyone could offer any insight or references based on my screenshot that would be great. Quick overview of the game:
It's a word game where you pick up tiles and click to play them and make words.
All tiles are instantiated from a prefab which contains a button and 2 text fields
When tiles are clicked/tapped they are tweened (using iTween) to the board.
Issues are only occurring with frame rate when playing on the device (iPad pro 10")
Are you instantiating the object from a prefab, or as a copy of another object in the scene? Pre-loading the object might help alleviate the issue. Don't think I've ever seen an instantiate take that much CPU time, but if you're having issues with it then it might help.
Answer by nati8oy · Feb 20, 2020 at 10:43 PM
Thanks for replying @AlphaGarg8447! I am instantiating from a prefab, but I have since pooled the objects and am using those now. That said, I found that parenting objects apparently take a bit of processing power as well. I have also found that there is a way to un-throttle the frame rate even on mobile devices using the below script. This actually solved a lot of my problems (visually) and was very handy so thought I'd share it. This code adde an FPS counter in the bottom right too but the real code you need is just in the Awake
function:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIFPSDisplay : MonoBehaviour
{
float deltaTime = 0.0f;
private void Awake()
{
Application.targetFrameRate = 60;
}
void Update()
{
deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
}
void OnGUI()
{
int w = Screen.width, h = Screen.height;
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0f, h-70f, (w - 50.0f), h * 2 / 100);
style.alignment = TextAnchor.LowerRight;
style.fontSize = h * 2 / 100;
style.normal.textColor = new Color(0f, 0f, 0f, 0.3f);
float msec = deltaTime * 1000.0f;
float fps = 1.0f / deltaTime;
//string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
string text = string.Format("{1:0.} fps", msec, fps);
GUI.Label(rect, text, style);
}
}
Your answer
Follow this Question
Related Questions
AICharacterControl Spike in Profiler 0 Answers
Mobile Performance Issues 0 Answers
3D Optimization Problem 1 Answer
Horrible Lag spike when Looking at an object that's showing GUI 1 Answer