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!
Ad

Recommended

Game Programming 05 - Development Tools
Game Programming 05 - Development Tools
Nick Pruehs
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content Generation
Nick Pruehs
 
Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great Game
Nick Pruehs
 
Game Programming 12 - Shaders
Game Programming 12 - Shaders
Nick Pruehs
 
Game Programming 06 - Automated Testing
Game Programming 06 - Automated Testing
Nick Pruehs
 
Game Development Challenges
Game Development Challenges
Nick Pruehs
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small Teams
Nick Pruehs
 
What Would Blizzard Do
What Would Blizzard Do
Nick Pruehs
 
School 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 Systems
Nick Pruehs
 
AAA Automated Testing
AAA Automated Testing
Francesco Carucci
 
Game Programming 01 - Introduction
Game Programming 01 - Introduction
Nick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool Development
Nick Pruehs
 
Game Programming 09 - AI
Game Programming 09 - AI
Nick Pruehs
 
Game 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 Systems
Nick Pruehs
 
Quality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality Matters
Marc Miquel
 
Entity Component Systems
Entity Component Systems
Yos Riady
 
Y1 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 engines
Lewis Brierley
 
Containerize your Blackbox tests
Containerize your Blackbox tests
Kevin Beeman
 
Y1 gd engine_terminologY
Y1 gd engine_terminologY
ElliotBlack
 
Owning 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 Fxui
rit2010
 
Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0
Željko Plesac
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjects
Giorgio Pomettini
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
slantsixgames
 
Game Programming 10 - Localization
Game Programming 10 - Localization
Nick Pruehs
 
Game Programming 03 - Git Flow
Game Programming 03 - Git Flow
Nick Pruehs
 
Component-Based Entity Systems (Demo)
Component-Based Entity Systems (Demo)
Nick Pruehs
 

More Related Content

What's hot (19)

School 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 Systems
Nick Pruehs
 
AAA Automated Testing
AAA Automated Testing
Francesco Carucci
 
Game Programming 01 - Introduction
Game Programming 01 - Introduction
Nick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool Development
Nick Pruehs
 
Game Programming 09 - AI
Game Programming 09 - AI
Nick Pruehs
 
Game 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 Systems
Nick Pruehs
 
Quality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality Matters
Marc Miquel
 
Entity Component Systems
Entity Component Systems
Yos Riady
 
Y1 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 engines
Lewis Brierley
 
Containerize your Blackbox tests
Containerize your Blackbox tests
Kevin Beeman
 
Y1 gd engine_terminologY
Y1 gd engine_terminologY
ElliotBlack
 
Owning 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 Fxui
rit2010
 
Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0
Željko Plesac
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjects
Giorgio Pomettini
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
slantsixgames
 
School 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 Systems
Nick Pruehs
 
Game Programming 01 - Introduction
Game Programming 01 - Introduction
Nick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool Development
Nick Pruehs
 
Game Programming 09 - AI
Game Programming 09 - AI
Nick Pruehs
 
Game 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 Systems
Nick Pruehs
 
Quality Assurance 1: Why Quality Matters
Quality Assurance 1: Why Quality Matters
Marc Miquel
 
Entity Component Systems
Entity Component Systems
Yos Riady
 
Y1 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 engines
Lewis Brierley
 
Containerize your Blackbox tests
Containerize your Blackbox tests
Kevin Beeman
 
Y1 gd engine_terminologY
Y1 gd engine_terminologY
ElliotBlack
 
Owning 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 Fxui
rit2010
 
Crash wars - The handling awakens v3.0
Crash wars - The handling awakens v3.0
Željko Plesac
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjects
Giorgio Pomettini
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
slantsixgames
 

Viewers also liked (10)

Game Programming 10 - Localization
Game Programming 10 - Localization
Nick Pruehs
 
Game Programming 03 - Git Flow
Game Programming 03 - Git Flow
Nick Pruehs
 
Component-Based Entity Systems (Demo)
Component-Based Entity Systems (Demo)
Nick Pruehs
 
Tool Development A - Git
Tool Development A - Git
Nick Pruehs
 
Game Programming 11 - Game Physics
Game Programming 11 - Game Physics
Nick Pruehs
 
Game 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 Pony
Nick Pruehs
 
Entity 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 2016
Simon Schmid
 
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Simon Schmid
 
Game Programming 10 - Localization
Game Programming 10 - Localization
Nick Pruehs
 
Game Programming 03 - Git Flow
Game Programming 03 - Git Flow
Nick Pruehs
 
Component-Based Entity Systems (Demo)
Component-Based Entity Systems (Demo)
Nick Pruehs
 
Tool Development A - Git
Tool Development A - Git
Nick Pruehs
 
Game Programming 11 - Game Physics
Game Programming 11 - Game Physics
Nick Pruehs
 
Game 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 Pony
Nick Pruehs
 
Entity 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 2016
Simon Schmid
 
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Simon Schmid
 
Ad

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

Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
ozlael ozlael
 
0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri
Adana Klima Servisi Bakım Montaj Taşıma Temizlik Tamir Arıza Teknik Servisleri
 
Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019
Unity Technologies
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Lviv Startup Club
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
DevGAMM Conference
 
Unity - Internals: memory and performance
Unity - Internals: memory and performance
Codemotion
 
Unity Internals: Memory and Performance
Unity Internals: Memory and Performance
DevGAMM Conference
 
Unity best practices (2013)
Unity best practices (2013)
Benjamin Robert
 
What the Unity engine documentation does not tell you?
What the Unity engine documentation does not tell you?
Łukasz Stępniak
 
Discussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source Components
PVS-Studio
 
Improve the performance of your Unity project using Graphics Performance Anal...
Improve the performance of your Unity project using Graphics Performance Anal...
Unity Technologies
 
Debugging multiplayer games
Debugging multiplayer games
Maciej Siniło
 
Practical Guide for Optimizing Unity on Mobiles
Practical Guide for Optimizing Unity on Mobiles
Valentin Simonov
 
It Doesn't Have to Be Hard: How to Fix Your Performance Woes
It Doesn't Have to Be Hard: How to Fix Your Performance Woes
Intel® Software
 
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
Unity Technologies Japan K.K.
 
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Codemotion
 
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Codemotion
 
Debug, Analyze and Optimize Games with Intel Tools
Debug, Analyze and Optimize Games with Intel Tools
Matteo Valoriani
 
Gamedev-grade debugging
Gamedev-grade debugging
Leszek Godlewski
 
[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity
William Hugo Yang
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
ozlael ozlael
 
Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019
Unity Technologies
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Lviv Startup Club
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
DevGAMM Conference
 
Unity - Internals: memory and performance
Unity - Internals: memory and performance
Codemotion
 
Unity Internals: Memory and Performance
Unity Internals: Memory and Performance
DevGAMM Conference
 
Unity best practices (2013)
Unity best practices (2013)
Benjamin Robert
 
What the Unity engine documentation does not tell you?
What the Unity engine documentation does not tell you?
Łukasz Stępniak
 
Discussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source Components
PVS-Studio
 
Improve the performance of your Unity project using Graphics Performance Anal...
Improve the performance of your Unity project using Graphics Performance Anal...
Unity Technologies
 
Debugging multiplayer games
Debugging multiplayer games
Maciej Siniło
 
Practical Guide for Optimizing Unity on Mobiles
Practical Guide for Optimizing Unity on Mobiles
Valentin Simonov
 
It Doesn't Have to Be Hard: How to Fix Your Performance Woes
It Doesn't Have to Be Hard: How to Fix Your Performance Woes
Intel® Software
 
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
【Unite 2017 Tokyo】パフォーマンス向上のためのスクリプトのベストプラクティス(note付き)
Unity Technologies Japan K.K.
 
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Codemotion
 
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Debug, Analyze and Optimize Games with Intel Tools - Matteo Valoriani - Codem...
Codemotion
 
Debug, Analyze and Optimize Games with Intel Tools
Debug, Analyze and Optimize Games with Intel Tools
Matteo Valoriani
 
[UniteKorea2013] Memory profiling in Unity
[UniteKorea2013] Memory profiling in Unity
William Hugo Yang
 
Ad

More from Nick Pruehs (10)

Unreal 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 Interface
Nick Pruehs
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
Nick Pruehs
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
Nick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
Nick Pruehs
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
Nick Pruehs
 
Game Programming - Cloud Development
Game Programming - Cloud Development
Nick Pruehs
 
Game Programming - Git
Game Programming - Git
Nick Pruehs
 
Game Programming 00 - Exams
Game Programming 00 - Exams
Nick Pruehs
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
Nick Pruehs
 
Unreal 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 Interface
Nick Pruehs
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
Nick Pruehs
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
Nick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
Nick Pruehs
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
Nick Pruehs
 
Game Programming - Cloud Development
Game Programming - Cloud Development
Nick Pruehs
 
Game Programming - Git
Game Programming - Git
Nick Pruehs
 
Game Programming 00 - Exams
Game Programming 00 - Exams
Nick Pruehs
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
Nick Pruehs
 

Recently uploaded (20)

Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 

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!