- Home /
Why do I have sporadic spikes in the profiler?
Hi! I have a problem with peaks in the profiler of my procedural generated World CPU and GPU. It's a lot of different code pieces witch spikes but some in particular. I show some screenshots below.
The game consist of about 4000 chunks all as separate game objects under a map game object which are loaded in using state machines and a threadpool.
Previous I did have a periodical spikes about every 20 - 30 frame by RenderTexture.SetActive. I did restart the editor and it's all gone now and I can not reproduce but will still mention it so you know.
Each screenshots represent one of the problematic spike types(from that code pice). I did previously also have problem with garbage collect but since i did start to reuse chunks that problem is gone.
The start function for Chunk looks as follows:
// Use this for initialization
void Start () {
_dirty=true;
materialList= chunkGrid.GetMaterialList();//(MaterialList)GameObject.Find("materialList").GetComponent("MaterialList");
if(meshData ==null){
meshData = new MeshData(materialList.materialList.Count);
}
if(meshNoneCollideData==null){
meshNoneCollideData = new MeshData(materialList.materialList.Count);
}
}
EDIT: I did get the error described above again after some work time in the editor!
Best regards /Johan
Try posting this question on the forum also, as it deserves attention and discussion.
The post is now also in the forum and is redirected to this thread.
I did dig in even deeper in the Chunk.start() code and did find that all of the process power is consumed by self of one object. How strange since it's almost no work to do.
I have boiled it down to this code.
using UnityEngine;
using System.Collections;
using System.Threading;
public class Spikes : $$anonymous$$onoBehaviour {
private $$anonymous$$eshFilter _filter;
private bool _threadDone = true;
private bool firstTime=true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(firstTime){
firstTime=false;
_filter = GetComponent<$$anonymous$$eshFilter>();
}
if(_threadDone){
Profiler.BeginSample("Update1");
Vector3[] vertices=_filter.shared$$anonymous$$esh.vertices;
Profiler.EndSample();
Profiler.BeginSample("Update2");
_threadDone=false;
Profiler.EndSample();
Profiler.BeginSample("Update3");
ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), vertices);
//ThreadPool.QueueUserWorkItem(DoWork, vertices);
Profiler.EndSample();
}
}
private void DoWork(object o){
Vector3 sum = new Vector3();
for (int i = 0; i<1000;i++){
foreach( Vector3 v in (Vector3[])o){
sum = v+sum;
}
}
_threadDone= true;
}
}
Add it to a capsule and duplicate the capsule 3 times so you have a total of 4 capsules and the spikes will appear. I have a quad core. Any Ideas? / Johan
Your answer
Follow this Question
Related Questions
Spikes for Render.Prepare 1 Answer
large sudden profiler spike 0 Answers
Garbage Collection (StackTraceUtility) - Profiler Spikes 1 Answer
What is "mesh count"? 0 Answers
Physics.Simulate taking a long time 1 Answer