220 likes | 428 Views
GOTTA GO FAST. Diagnosing Performance Problems in Unity3D Richard Fine @ London Unity User Group August 2013. Why?. Uh. What?. Sufficiently high overall framerate Ideally 60+ FPS on desktop platforms 30+ FPS on console and mobile Smooth framerate
E N D
GOTTA GO FAST • Diagnosing Performance Problems in Unity3D • Richard Fine @ London Unity User Group August 2013
Why? • Uh...
What? • Sufficiently high overall framerate • Ideally 60+ FPS on desktop platforms • 30+ FPS on console and mobile • Smooth framerate • Lower, smoother framerate > higher, uneven framerate • Responsive, wait-free experience
Sidebar: FPS • Avoid it - use seconds per frame instead • 30FPS -> 25FPS drop vs 60FPS -> 50FPS drop: • Real times: • 30FPS: 33.3ms 25FPS: 40ms +6.6ms/frame • 60FPS: 16.6ms 50FPS: 20ms +3.3ms/frame • Actually only half the extra work being done!
When? • Integrate it into development • Identify frametime targets/budgets • Run experiments on the target hardware • Impacts development speed
How? • Do fewer things • Do crappier things • Do more than one thing at a time • Do things over multiple frames
Where? • Need to know where to focus your efforts • Efficient use of dev time • Bottleneck principle
Tool #1: Stats Window • Available in all versions of Unity • Quick overview of (mostly graphics) stats • Most important numbers at the top: • Main Thread time • Render Thread time
Time Thread times? Wot? Physics Scripts Culling Render Submission Draw Calls Actual Rendering Main Thread Render Thread GPU
Physics Scripts Time Culling Render Submission Draw Calls Actual Rendering Physics Scripts Culling Render Submission Draw Calls Actual Rendering Physics Scripts Culling Render Submission Draw Calls Actual Rendering
Physics Time Physics Scripts Culling Render Submission Draw Calls ActualRendering Actual Rendering
Physics Time Physics Scripts Culling Render Submission Draw Calls ActualRendering Physics Scripts Culling Render Submission Draw Calls ActualRendering
Physics Time Physics Scripts Culling Render Submission Draw Calls ActualRendering Physics Scripts Wait... Culling Render Submission Draw Calls ActualRendering
Physics Time Physics Scripts Culling Render Submission Draw Calls ActualRendering Physics Scripts Wait... Culling Render Submission Draw Calls ActualRendering
Pick your battleground Physics • If you’re Main Thread bound: • ‘Main Thread’ highest in Stats window • Focus on Physics or user scripts • Having tons of active objects can cause this too • Layer-based culling isn’t fast! Scripts Culling Render Submission Draw Calls Actual Rendering Main Thread Render Thread GPU
Pick your battleground Physics • If you’re Render Thread bound: • ‘Renderer’ highest in Stats window • Too many draw calls and/or complex materials • “Classic” Unity optimization advice - atlas materials, batch objects, improve culling, etc Scripts Culling Render Submission Draw Calls Actual Rendering Main Thread Render Thread GPU
Pick your battleground Physics • If you’re GPU bound: • Shows as Main Thread time, due to the wait. (Sometimes). • Too many vertices, triangles, fragments... • See if it goes away when you change GPU workload • Classic GPU advice: fewer polys, smaller textures, etc Scripts Culling Render Submission Draw Calls Actual Rendering Main Thread Render Thread GPU
Tool #2: Unity Profiler • In-depth breakdown of where time is being spent • Shows other resource levels • Unity Pro only
Unity Profiler Notes • Prefer builds over in-editor profiling for subtle timings • Deep Profiling distorts times heavily • Look into adding in-build capture + load into Editor
In Conclusion... • Understand where the work is being done • Learn what ‘normal’ looks like • Experiment • Check frequently to help isolate when it changed • You can go deeper...
Any Questions? Richard Fine 2013 rfine@tbrf.net @Superpig