SlideShare a Scribd company logo
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

What's hot

School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
Nick Pruehs
 
Style & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsStyle & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity Systems
Nick Pruehs
 
AAA Automated Testing
AAA Automated TestingAAA Automated Testing
AAA Automated Testing
Francesco Carucci
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - Introduction
Nick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool Development
Nick Pruehs
 
Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AI
Nick Pruehs
 
Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design Principles
Nick Pruehs
 
Game Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsGame Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity Systems
Nick Pruehs
 
Quality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality MattersQuality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality Matters
Marc Miquel
 
Entity Component Systems
Entity Component SystemsEntity Component Systems
Entity Component Systems
Yos Riady
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
Lewis Brierley
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
Lewis Brierley
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
Kevin Beeman
 
Y1 gd engine_terminologY
Y1 gd engine_terminologYY1 gd engine_terminologY
Y1 gd engine_terminologY
ElliotBlack
 
Owning windows 8 with human interface devices
Owning windows 8 with human interface devicesOwning windows 8 with human interface devices
Owning windows 8 with human interface devices
Nikhil Mittal
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
rit2010
 
Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0
Željko Plesac
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjectsRapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjects
Giorgio Pomettini
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
slantsixgames
 

What's hot (19)

School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Style & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsStyle & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity Systems
 
AAA Automated Testing
AAA Automated TestingAAA Automated Testing
AAA Automated Testing
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - Introduction
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool Development
 
Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AI
 
Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design Principles
 
Game Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsGame Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity Systems
 
Quality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality MattersQuality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality Matters
 
Entity Component Systems
Entity Component SystemsEntity Component Systems
Entity Component Systems
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
 
Y1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game enginesY1 gd engine_terminology ig2 game engines
Y1 gd engine_terminology ig2 game engines
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
 
Y1 gd engine_terminologY
Y1 gd engine_terminologYY1 gd engine_terminologY
Y1 gd engine_terminologY
 
Owning windows 8 with human interface devices
Owning windows 8 with human interface devicesOwning windows 8 with human interface devices
Owning windows 8 with human interface devices
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
 
Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjectsRapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjects
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
 

Viewers also liked

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

Viewers also liked (10)

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

Similar to Game Programming 13 - Debugging & Performance Optimization

Spaghetti gate
Spaghetti gateSpaghetti gate
Spaghetti gate
Jon Bachelor
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
Andrew Petukhov
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
Vadym Lotar
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Community
 
How many ways to monitor oracle golden gate-Collaborate 14
How many ways to monitor oracle golden gate-Collaborate 14How many ways to monitor oracle golden gate-Collaborate 14
How many ways to monitor oracle golden gate-Collaborate 14
Bobby Curtis
 
Don't Suck at Building Stuff - Mykel Alvis at Puppet Camp Altanta
Don't Suck at Building Stuff  - Mykel Alvis at Puppet Camp AltantaDon't Suck at Building Stuff  - Mykel Alvis at Puppet Camp Altanta
Don't Suck at Building Stuff - Mykel Alvis at Puppet Camp Altanta
Puppet
 
Exception handling
Exception handlingException handling
Exception handling
Abhishek Pachisia
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at Scale
Kris Buytaert
 
Why Software Test Performance Matters
Why Software Test Performance MattersWhy Software Test Performance Matters
Why Software Test Performance Matters
Solano Labs
 
Continuous Integration In Php
Continuous Integration In PhpContinuous Integration In Php
Continuous Integration In Php
Wilco Jansen
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
CocoaHeads France
 
High Reliabilty Systems
High Reliabilty SystemsHigh Reliabilty Systems
High Reliabilty Systems
LloydMoore
 
The Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingThe Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security Testing
Matt Tesauro
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
Sam Bowne
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ihor Banadiga
 
Head first android apps dev tools
Head first android apps dev toolsHead first android apps dev tools
Head first android apps dev tools
Shaka Huang
 
CNIT 126: 8: Debugging
CNIT 126: 8: DebuggingCNIT 126: 8: Debugging
CNIT 126: 8: Debugging
Sam Bowne
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
Peter Kofler
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and Flickr
John Allspaw
 
A lean automation blueprint for testing in continuous delivery
A lean automation blueprint for testing in continuous deliveryA lean automation blueprint for testing in continuous delivery
A lean automation blueprint for testing in continuous delivery
Sauce Labs
 

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

Spaghetti gate
Spaghetti gateSpaghetti gate
Spaghetti gate
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph
 
How many ways to monitor oracle golden gate-Collaborate 14
How many ways to monitor oracle golden gate-Collaborate 14How many ways to monitor oracle golden gate-Collaborate 14
How many ways to monitor oracle golden gate-Collaborate 14
 
Don't Suck at Building Stuff - Mykel Alvis at Puppet Camp Altanta
Don't Suck at Building Stuff  - Mykel Alvis at Puppet Camp AltantaDon't Suck at Building Stuff  - Mykel Alvis at Puppet Camp Altanta
Don't Suck at Building Stuff - Mykel Alvis at Puppet Camp Altanta
 
Exception handling
Exception handlingException handling
Exception handling
 
Deploying software at Scale
Deploying software at ScaleDeploying software at Scale
Deploying software at Scale
 
Why Software Test Performance Matters
Why Software Test Performance MattersWhy Software Test Performance Matters
Why Software Test Performance Matters
 
Continuous Integration In Php
Continuous Integration In PhpContinuous Integration In Php
Continuous Integration In Php
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
High Reliabilty Systems
High Reliabilty SystemsHigh Reliabilty Systems
High Reliabilty Systems
 
The Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security TestingThe Final Frontier, Automating Dynamic Security Testing
The Final Frontier, Automating Dynamic Security Testing
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
 
Head first android apps dev tools
Head first android apps dev toolsHead first android apps dev tools
Head first android apps dev tools
 
CNIT 126: 8: Debugging
CNIT 126: 8: DebuggingCNIT 126: 8: Debugging
CNIT 126: 8: Debugging
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and Flickr
 
A lean automation blueprint for testing in continuous delivery
A lean automation blueprint for testing in continuous deliveryA lean automation blueprint for testing in continuous delivery
A lean automation blueprint for testing in continuous delivery
 

More from Nick Pruehs

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Nick Pruehs
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
Nick Pruehs
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
Nick Pruehs
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
Nick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
Nick Pruehs
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
Nick Pruehs
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud Development
Nick Pruehs
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - Git
Nick Pruehs
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - Exams
Nick Pruehs
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsTool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
Nick Pruehs
 

More from Nick Pruehs (10)

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud Development
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - Git
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - Exams
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsTool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
 

Recently uploaded

Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 

Recently uploaded (20)

Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 

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!