Game Programming
Debugging & Performance Optimization
Nick Prühs
Objectives
• To get an overview of techniques for preventing bugs beforehand
• To learn how to track down and properly remove bugs from your
code
• To understand possible performance bottlenecks
2 / 55
Why you should always start debugging immediately
• Code entropy says your code will get worse, all the time, unless you
actively invest in preventing that
• Broken windows theory says the worse your code is, the worse it will
become
• Tracking down bugs is harder in a larger code base
• Tracking down bugs is harder in a buggy code base
3 / 55
Code Quality Tools
4 / 55
Code Quality Tools
5 / 55
Code Quality Tools
6 / 55
/// <summary>
/// Attaches the passed component to the entity with the specified id.
/// Note that this manager does not check whether the specified id is valid.
/// </summary>
/// <exception cref="ArgumentNullException">
/// Passed component is null.
/// </exception>
/// <exception cref="InvalidOperationException">
/// There is already a component of the same type attached.
/// </exception>
public void AddComponent(int entityId, IEntityComponent component)
{
if (component == null)
{
throw new ArgumentNullException("component");
}
if (this.components.ContainsKey(entityId))
{
throw new InvalidOperationException(
"There is already a component of type " + component.GetType() + " attached to entity with id "
+ entityId + ".");
}
this.components.Add(entityId, component);
this.OnComponentAdded(entityId, component);
}
You need a repro. Period.
How can you be sure you’ve fixed it?
7 / 55
Stack Traces
Object reference not set to an instance of an object
at LifeApplication.Initializer.CreateManagers () [0x00488] in
Initializer.cs:481
at LifeApplication.Initializer.OnLoad () [0x00016] in
Initializer.cs:235
8 / 55
What’s null here?
// Initialize progress manager.
var progressConfig = new ProgressConfig(this.unityLoader.Version.Code);
if (this.config.Progress.Encrypt)
{
progressConfig.SetEncryption(
this.config.Progress.Encryption.EncryptKey,
this.config.Progress.Encryption.EncryptIv);
}
9 / 55
What’s null here?
// Initialize progress manager.
var progressConfig = new ProgressConfig(this.unityLoader.Version.Code);
if (this.config.Progress.Encrypt)
{
progressConfig.SetEncryption(
this.config.Progress.Encryption.EncryptKey,
this.config.Progress.Encryption.EncryptIv);
}
10 / 55
What’s null here?
// Initialize progress manager.
var progressConfig = new ProgressConfig(this.unityLoader.Version.Code);
if (this.config.Progress.Encrypt)
{
progressConfig.SetEncryption(
this.config.Progress.Encryption.EncryptKey,
this.config.Progress.Encryption.EncryptIv);
}
11 / 55
What’s null here?
// Initialize progress manager.
var progressConfig = new ProgressConfig(this.unityLoader.Version.Code);
if (this.config.Progress.Encrypt)
{
progressConfig.SetEncryption(
this.config.Progress.Encryption.EncryptKey,
this.config.Progress.Encryption.EncryptIv);
}
12 / 55
What’s null here?
// Initialize progress manager.
var progressConfig = new ProgressConfig(this.unityLoader.Version.Code);
if (this.config.Progress.Encrypt)
{
progressConfig.SetEncryption(
this.config.Progress.Encryption.EncryptKey,
this.config.Progress.Encryption.EncryptIv);
}
13 / 55
What’s null here?
// Initialize progress manager.
var progressConfig = new ProgressConfig(this.unityLoader.Version.Code);
if (this.config.Progress.Encrypt)
{
progressConfig.SetEncryption(
this.config.Progress.Encryption.EncryptKey,
this.config.Progress.Encryption.EncryptIv);
}
14 / 55
Divide-and-conquer
15 / 55
Divide-and-conquer
16 / 55
Divide-and-conquer
17 / 55
Divide-and-conquer
18 / 55
Divide-and-conquer
19 / 55
Divide-and-conquer
20 / 55
Conditional Breakpoints
21 / 55
Logging
22 / 55
On-Screen
23 / 55
Crash Dump Analaysis
24 / 55
C:Program FilesProcdump>procdump.exe -ma -i D:TempDumps
ProcDump v7.0 - Writes process dump files
Copyright (C) 2009-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
With contributions from Andrew Richards
Set to:
HKLMSOFTWAREMicrosoftWindows NTCurrentVersionAeDebug
(REG_SZ) Auto = 1
(REG_SZ) Debugger = "C:Program FilesProcdumpprocdump.exe" -accepteula -ma
-j "D:TempDumps" %ld %ld %p
Set to:
HKLMSOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionAeDebug
(REG_SZ) Auto = 1
(REG_SZ) Debugger = "C:Program FilesProcdumpprocdump.exe" -accepteula -ma
-j "D:TempDumps" %ld %ld %p
ProcDump is now set as the Just-in-time (AeDebug) debugger.
Crash Dump Analaysis
25 / 55
C:Program FilesProcdump>procdump.exe -u
ProcDump v7.0 - Writes process dump files
Copyright (C) 2009-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
With contributions from Andrew Richards
Reset to:
HKLMSOFTWAREMicrosoftWindows NTCurrentVersionAeDebug
(REG_SZ) Auto = <deleted>
(REG_SZ) Debugger = "C:WINDOWSsystem32vsjitdebugger.exe" -p %ld -e %ld
Reset to:
HKLMSOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionAeDebug
(REG_SZ) Auto = <deleted>
(REG_SZ) Debugger = "C:WINDOWSsystem32vsjitdebugger.exe" -p %ld -e %ld
ProcDump is no longer the Just-in-time (AeDebug) debugger.
Crash Dump Analaysis
26 / 55
Deferencing a nullptr that will cause a crash
Crash Dump Analaysis
27 / 55
Minidump File Summary in Visual Studio
Crash Dump Analaysis
28 / 55
Debugging a Minidump in Visual Studio
Pair Programming
29 / 55
Source: University of Utah, UIT
And if nothings helps …
30 / 55
And if nothings helps …
31 / 55
TRY AGAIN
TOMORROW!
Some are really nasty …
• Remote systems
• Race conditions
• Mobile development, embedded systems, drivers
• “Release Mode only” bugs
32 / 55
Quoting My Tutor
“If the bug is not where you expect it to be,
you better start looking for it where you’re not expecting it to be.”
- Hagen Peters
33 / 55
Why you should never start optimizing immediately
• Your code base will change over time, a lot, most likely removing
some of the code you’ve spent time on optimizing
• Optimized code tends to be hard to read
▪ … and thus, hard to debug.
34 / 55
Performance Optimization
1. Profile first!
35 / 55
Performance Optimization
1. Profile first!
2. Profile again!
36 / 55
Performance Optimization
1. Profile first!
2. Profile again!
3. Identify the bottlenecks: GPU vs. CPU vs. Memory
37 / 55
38 / 55
GPU Bottleneck
39 / 55
Frame Debugger
40 / 55
Frame Debugger
41 / 55
Frame Debugger
42 / 55
Frame Debugger
43 / 55
Frame Debugger
44 / 5
Fighting CPU Bottlenecks
Pooling
Trades memory for CPU performance.
Re-uses objects to prevent costly construction and destruction.
Requires proper (cheap) reset of pooled objects.
45 / 55
Fighting CPU Bottlenecks
Caching
Trades memory for CPU performance.
Stores computed values for later use.
Requires proper cache invalidation whenever the input changes.
46 / 55
Fighting CPU Bottlenecks
Bucketing
Trades accuracy for CPU performance.
Distributes computations across multiple frames by dividing operation
into multiple input sets.
Can only be applied if player doesn’t notice difference immediately (e.g.
updating AI just twice per second).
47 / 55
Memory Bottleneck
48 / 55
Memory Bottleneck
49 / 55
Memory Bottleneck
50 / 55
Gotcha!
Always turn off logging before
profiling!
Otherwise, disk I/O will lead to
false results.
51 / 55
Hint
If no native profiling tools are
available (or applicable), you can
always fall back to utility classes
such as
System.Diagnostics.Stopwatch.
52 / 55
Memory Leaks
• allocated memory that is never released
▪ in most cases, the reference or pointer is not even available any
more
▪ if occurring on a regular basis (e.g. every time a level is loaded),
will eventually fill up all available memory and crash the game
• in Ansi C: “no malloc without free”
• in C++: “no new without delete”
▪ in modern C++, usually achieved by the means of smart pointers
Gotcha!
Managed runtime
environments can leak
memory, too!
54 / 55
Memory Leaks
• make sure to always remove all registered event handlers in
languages like C#
• more complicated runtime environments can represent unique
challenges
▪ e.g. Mono heap in Unity
• it might be a good idea to return to an “empty scene” once in a while
and verify all memory has been properly cleaned up
Memory Leak in Unity
Memory Leak in Unity
References
• McShaffry. Debugging Your Game … or “That’s not supposed to
happen!”. Austin Game Conference, 2003.
58 / 55
Thank you!
http://www.npruehs.de
https://github.com/npruehs
@npruehs
nick.pruehs@daedalic.com
5 Minute Review Session
• Why should you always start debugging immediately?
• Why should you never start optimizing immediately?
• Name a few tools and approaches for tracking down broken code!
• How do you know whether you’ve got an GPU, CPU or memory
bottleneck?
• Name a few techniques for fighting CPU bottlenecks!

More Related Content

PDF
Game Programming 05 - Development Tools
PDF
Game Programming 07 - Procedural Content Generation
PDF
Eight Rules for Making Your First Great Game
PDF
Game Programming 12 - Shaders
PDF
Game Programming 06 - Automated Testing
PDF
Game Development Challenges
PDF
Scrum - but... Agile Game Development in Small Teams
PDF
What Would Blizzard Do
Game Programming 05 - Development Tools
Game Programming 07 - Procedural Content Generation
Eight Rules for Making Your First Great Game
Game Programming 12 - Shaders
Game Programming 06 - Automated Testing
Game Development Challenges
Scrum - but... Agile Game Development in Small Teams
What Would Blizzard Do

What's hot (19)

PDF
School For Games 2015 - Unity Engine Basics
PDF
Style & Design Principles 03 - Component-Based Entity Systems
PPT
AAA Automated Testing
PDF
Game Programming 01 - Introduction
PDF
Game Programming 08 - Tool Development
PDF
Game Programming 09 - AI
PDF
Game Programming 04 - Style & Design Principles
PDF
Game Programming 02 - Component-Based Entity Systems
PDF
Quality Assurance 1: Why Quality Matters
PDF
Entity Component Systems
DOCX
Y1 gd engine_terminology ig2 game engines
DOCX
Y1 gd engine_terminology ig2 game engines
PPTX
Containerize your Blackbox tests
DOC
Y1 gd engine_terminologY
PPTX
Owning windows 8 with human interface devices
ODP
Alexandre Iline Rit 2010 Java Fxui
PDF
Crash wars - The handling awakens v3.0
PDF
Rapid prototyping with ScriptableObjects
PPTX
Maximize Your Production Effort (English)
School For Games 2015 - Unity Engine Basics
Style & Design Principles 03 - Component-Based Entity Systems
AAA Automated Testing
Game Programming 01 - Introduction
Game Programming 08 - Tool Development
Game Programming 09 - AI
Game Programming 04 - Style & Design Principles
Game Programming 02 - Component-Based Entity Systems
Quality Assurance 1: Why Quality Matters
Entity Component Systems
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
Containerize your Blackbox tests
Y1 gd engine_terminologY
Owning windows 8 with human interface devices
Alexandre Iline Rit 2010 Java Fxui
Crash wars - The handling awakens v3.0
Rapid prototyping with ScriptableObjects
Maximize Your Production Effort (English)
Ad

Viewers also liked (10)

PDF
Game Programming 10 - Localization
PDF
Game Programming 03 - Git Flow
PDF
Component-Based Entity Systems (Demo)
PDF
Tool Development A - Git
PDF
Game Programming 11 - Game Physics
PDF
Game Models - A Different Approach
PDF
Designing an actor model game architecture with Pony
PDF
Entity System Architecture with Unity - Unite Europe 2015
PDF
ECS architecture with Unity by example - Unite Europe 2016
PDF
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Game Programming 10 - Localization
Game Programming 03 - Git Flow
Component-Based Entity Systems (Demo)
Tool Development A - Git
Game Programming 11 - Game Physics
Game Models - A Different Approach
Designing an actor model game architecture with Pony
Entity System Architecture with Unity - Unite Europe 2015
ECS architecture with Unity by example - Unite Europe 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Ad

Similar to Game Programming 13 - Debugging & Performance Optimization (20)

PPTX
Optimizing mobile applications - Ian Dundore, Mark Harkness
PPTX
Tales from the Optimization Trenches - Unite Copenhagen 2019
PPTX
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
PDF
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
PPTX
Unity - Internals: memory and performance
PDF
Unity Internals: Memory and Performance
PPTX
Unity best practices (2013)
PDF
What the Unity engine documentation does not tell you?
PDF
Discussing Errors in Unity3D's Open-Source Components
PPTX
Improve the performance of your Unity project using Graphics Performance Anal...
PPTX
Debugging multiplayer games
PPTX
Practical Guide for Optimizing Unity on Mobiles
PDF
It Doesn't Have to Be Hard: How to Fix Your Performance Woes
PDF
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
PDF
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
PDF
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
PDF
Debug, Analyze and Optimize Games with Intel Tools
PDF
Gamedev-grade debugging
PPTX
[UniteKorea2013] Memory profiling in Unity
Optimizing mobile applications - Ian Dundore, Mark Harkness
Tales from the Optimization Trenches - Unite Copenhagen 2019
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Unity - Internals: memory and performance
Unity Internals: Memory and Performance
Unity best practices (2013)
What the Unity engine documentation does not tell you?
Discussing Errors in Unity3D's Open-Source Components
Improve the performance of your Unity project using Graphics Performance Anal...
Debugging multiplayer games
Practical Guide for Optimizing Unity on Mobiles
It Doesn't Have to Be Hard: How to Fix Your Performance Woes
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Debug, Analyze and Optimize Games with Intel Tools
Gamedev-grade debugging
[UniteKorea2013] Memory profiling in Unity

More from Nick Pruehs (10)

PDF
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
PDF
Unreal Engine Basics 05 - User Interface
PDF
Unreal Engine Basics 04 - Behavior Trees
PDF
Unreal Engine Basics 03 - Gameplay
PDF
Unreal Engine Basics 02 - Unreal Editor
PDF
Unreal Engine Basics 01 - Game Framework
PDF
Game Programming - Cloud Development
PDF
Game Programming - Git
PDF
Game Programming 00 - Exams
PDF
Tool Development 10 - MVVM, Tool Chains
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 01 - Game Framework
Game Programming - Cloud Development
Game Programming - Git
Game Programming 00 - Exams
Tool Development 10 - MVVM, Tool Chains

Recently uploaded (20)

PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Five Habits of High-Impact Board Members
DOCX
search engine optimization ppt fir known well about this
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
Architecture types and enterprise applications.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
A proposed approach for plagiarism detection in Myanmar Unicode text
A contest of sentiment analysis: k-nearest neighbor versus neural network
Five Habits of High-Impact Board Members
search engine optimization ppt fir known well about this
Improvisation in detection of pomegranate leaf disease using transfer learni...
sbt 2.0: go big (Scala Days 2025 edition)
OpenACC and Open Hackathons Monthly Highlights July 2025
TEXTILE technology diploma scope and career opportunities
UiPath Agentic Automation session 1: RPA to Agents
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Basics of Cloud Computing - Cloud Ecosystem
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Architecture types and enterprise applications.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
Benefits of Physical activity for teenagers.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Developing a website for English-speaking practice to English as a foreign la...
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
Zenith AI: Advanced Artificial Intelligence

Game Programming 13 - Debugging & Performance Optimization

  • 1. Game Programming Debugging & Performance Optimization Nick Prühs
  • 2. Objectives • To get an overview of techniques for preventing bugs beforehand • To learn how to track down and properly remove bugs from your code • To understand possible performance bottlenecks 2 / 55
  • 3. Why you should always start debugging immediately • Code entropy says your code will get worse, all the time, unless you actively invest in preventing that • Broken windows theory says the worse your code is, the worse it will become • Tracking down bugs is harder in a larger code base • Tracking down bugs is harder in a buggy code base 3 / 55
  • 6. Code Quality Tools 6 / 55 /// <summary> /// Attaches the passed component to the entity with the specified id. /// Note that this manager does not check whether the specified id is valid. /// </summary> /// <exception cref="ArgumentNullException"> /// Passed component is null. /// </exception> /// <exception cref="InvalidOperationException"> /// There is already a component of the same type attached. /// </exception> public void AddComponent(int entityId, IEntityComponent component) { if (component == null) { throw new ArgumentNullException("component"); } if (this.components.ContainsKey(entityId)) { throw new InvalidOperationException( "There is already a component of type " + component.GetType() + " attached to entity with id " + entityId + "."); } this.components.Add(entityId, component); this.OnComponentAdded(entityId, component); }
  • 7. You need a repro. Period. How can you be sure you’ve fixed it? 7 / 55
  • 8. Stack Traces Object reference not set to an instance of an object at LifeApplication.Initializer.CreateManagers () [0x00488] in Initializer.cs:481 at LifeApplication.Initializer.OnLoad () [0x00016] in Initializer.cs:235 8 / 55
  • 9. What’s null here? // Initialize progress manager. var progressConfig = new ProgressConfig(this.unityLoader.Version.Code); if (this.config.Progress.Encrypt) { progressConfig.SetEncryption( this.config.Progress.Encryption.EncryptKey, this.config.Progress.Encryption.EncryptIv); } 9 / 55
  • 10. What’s null here? // Initialize progress manager. var progressConfig = new ProgressConfig(this.unityLoader.Version.Code); if (this.config.Progress.Encrypt) { progressConfig.SetEncryption( this.config.Progress.Encryption.EncryptKey, this.config.Progress.Encryption.EncryptIv); } 10 / 55
  • 11. What’s null here? // Initialize progress manager. var progressConfig = new ProgressConfig(this.unityLoader.Version.Code); if (this.config.Progress.Encrypt) { progressConfig.SetEncryption( this.config.Progress.Encryption.EncryptKey, this.config.Progress.Encryption.EncryptIv); } 11 / 55
  • 12. What’s null here? // Initialize progress manager. var progressConfig = new ProgressConfig(this.unityLoader.Version.Code); if (this.config.Progress.Encrypt) { progressConfig.SetEncryption( this.config.Progress.Encryption.EncryptKey, this.config.Progress.Encryption.EncryptIv); } 12 / 55
  • 13. What’s null here? // Initialize progress manager. var progressConfig = new ProgressConfig(this.unityLoader.Version.Code); if (this.config.Progress.Encrypt) { progressConfig.SetEncryption( this.config.Progress.Encryption.EncryptKey, this.config.Progress.Encryption.EncryptIv); } 13 / 55
  • 14. What’s null here? // Initialize progress manager. var progressConfig = new ProgressConfig(this.unityLoader.Version.Code); if (this.config.Progress.Encrypt) { progressConfig.SetEncryption( this.config.Progress.Encryption.EncryptKey, this.config.Progress.Encryption.EncryptIv); } 14 / 55
  • 24. Crash Dump Analaysis 24 / 55 C:Program FilesProcdump>procdump.exe -ma -i D:TempDumps ProcDump v7.0 - Writes process dump files Copyright (C) 2009-2014 Mark Russinovich Sysinternals - www.sysinternals.com With contributions from Andrew Richards Set to: HKLMSOFTWAREMicrosoftWindows NTCurrentVersionAeDebug (REG_SZ) Auto = 1 (REG_SZ) Debugger = "C:Program FilesProcdumpprocdump.exe" -accepteula -ma -j "D:TempDumps" %ld %ld %p Set to: HKLMSOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionAeDebug (REG_SZ) Auto = 1 (REG_SZ) Debugger = "C:Program FilesProcdumpprocdump.exe" -accepteula -ma -j "D:TempDumps" %ld %ld %p ProcDump is now set as the Just-in-time (AeDebug) debugger.
  • 25. Crash Dump Analaysis 25 / 55 C:Program FilesProcdump>procdump.exe -u ProcDump v7.0 - Writes process dump files Copyright (C) 2009-2014 Mark Russinovich Sysinternals - www.sysinternals.com With contributions from Andrew Richards Reset to: HKLMSOFTWAREMicrosoftWindows NTCurrentVersionAeDebug (REG_SZ) Auto = <deleted> (REG_SZ) Debugger = "C:WINDOWSsystem32vsjitdebugger.exe" -p %ld -e %ld Reset to: HKLMSOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionAeDebug (REG_SZ) Auto = <deleted> (REG_SZ) Debugger = "C:WINDOWSsystem32vsjitdebugger.exe" -p %ld -e %ld ProcDump is no longer the Just-in-time (AeDebug) debugger.
  • 26. Crash Dump Analaysis 26 / 55 Deferencing a nullptr that will cause a crash
  • 27. Crash Dump Analaysis 27 / 55 Minidump File Summary in Visual Studio
  • 28. Crash Dump Analaysis 28 / 55 Debugging a Minidump in Visual Studio
  • 29. Pair Programming 29 / 55 Source: University of Utah, UIT
  • 30. And if nothings helps … 30 / 55
  • 31. And if nothings helps … 31 / 55 TRY AGAIN TOMORROW!
  • 32. Some are really nasty … • Remote systems • Race conditions • Mobile development, embedded systems, drivers • “Release Mode only” bugs 32 / 55
  • 33. Quoting My Tutor “If the bug is not where you expect it to be, you better start looking for it where you’re not expecting it to be.” - Hagen Peters 33 / 55
  • 34. Why you should never start optimizing immediately • Your code base will change over time, a lot, most likely removing some of the code you’ve spent time on optimizing • Optimized code tends to be hard to read ▪ … and thus, hard to debug. 34 / 55
  • 36. Performance Optimization 1. Profile first! 2. Profile again! 36 / 55
  • 37. Performance Optimization 1. Profile first! 2. Profile again! 3. Identify the bottlenecks: GPU vs. CPU vs. Memory 37 / 55
  • 45. Fighting CPU Bottlenecks Pooling Trades memory for CPU performance. Re-uses objects to prevent costly construction and destruction. Requires proper (cheap) reset of pooled objects. 45 / 55
  • 46. Fighting CPU Bottlenecks Caching Trades memory for CPU performance. Stores computed values for later use. Requires proper cache invalidation whenever the input changes. 46 / 55
  • 47. Fighting CPU Bottlenecks Bucketing Trades accuracy for CPU performance. Distributes computations across multiple frames by dividing operation into multiple input sets. Can only be applied if player doesn’t notice difference immediately (e.g. updating AI just twice per second). 47 / 55
  • 51. Gotcha! Always turn off logging before profiling! Otherwise, disk I/O will lead to false results. 51 / 55
  • 52. Hint If no native profiling tools are available (or applicable), you can always fall back to utility classes such as System.Diagnostics.Stopwatch. 52 / 55
  • 53. Memory Leaks • allocated memory that is never released ▪ in most cases, the reference or pointer is not even available any more ▪ if occurring on a regular basis (e.g. every time a level is loaded), will eventually fill up all available memory and crash the game • in Ansi C: “no malloc without free” • in C++: “no new without delete” ▪ in modern C++, usually achieved by the means of smart pointers
  • 54. Gotcha! Managed runtime environments can leak memory, too! 54 / 55
  • 55. Memory Leaks • make sure to always remove all registered event handlers in languages like C# • more complicated runtime environments can represent unique challenges ▪ e.g. Mono heap in Unity • it might be a good idea to return to an “empty scene” once in a while and verify all memory has been properly cleaned up
  • 56. Memory Leak in Unity
  • 57. Memory Leak in Unity
  • 58. References • McShaffry. Debugging Your Game … or “That’s not supposed to happen!”. Austin Game Conference, 2003. 58 / 55
  • 60. 5 Minute Review Session • Why should you always start debugging immediately? • Why should you never start optimizing immediately? • Name a few tools and approaches for tracking down broken code! • How do you know whether you’ve got an GPU, CPU or memory bottleneck? • Name a few techniques for fighting CPU bottlenecks!