Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
IL2CPP: Profiling and Debugging
Jonathan Chambers and
Josh Peterson
Agenda
The Abridged Version
IL2CPP
Where is IL2CPP?
Creating IL2CPP
How do we make IL2CPP?
Fundamental principle: Test first
• Unit tests - C++ and C# (~500)
• Integration tests (~2000)
• Platform integration test...
Tools we use
• We debug with an IL2CPP standalone player
• We check build time and size against real projects
Internal tools
Internal organization of libil2cpp code
Internal
Calls
Generated
Code
PALVM
iOS
Windows
Other
Platform
Our goal: move fast
Photo credit: Alvesgaspar (CC BY-SA 3.0)
Debugging script code
with IL2CPP
Best option: Debug code in the editor
Acceptable option: Debug on device with Mono backend
Debugging script code with IL2C...
When to debug generated C++ code
An exception occurs only
on the device
Marshaling
Interaction with native code
Deep dive: Debugging a
managed exception in
generated C++ code
• The converted code is the IL code, not C# code
• Filter underscore characters from names
• Sanity check often
• Understa...
• Debugging generated C++ code is probably not a
technique to use often.
• Generated code will change in newer versions.
•...
Check out our IL2CPP Internals blog series!
Debugging tips for generated code - http://
blogs.unity3d.com/2015/05/20/il2cp...
Performance and Profiling
We make things fast for you!
The Good News
Make it small and make it fast!
Speed *and* Size
Make your code fast in general
.Net Profiler
Make your code fast in Unity
Unity Profiler
Make your code fast on device
Native Profiler
var md5 = MD5.Create();

var values = new byte[1024*1024];

var random = new Random(100);

random.NextBytes(values);



Ti...
MD5 Hash
0ms
25ms
50ms
75ms
100ms
iPod 4G
Unity Mono IL2CPP
MD5 Hash
0ms
25ms
50ms
75ms
100ms
iPod 4G iPhone 6
Unity Mono IL2CPP
struct Vector2

{

public float X;

public float Y;



public Vector2(float x, float y)

{

X = x;

Y = x;

}



public fl...
const int kNumItems = 1000000;

var vals = new Vector2[kNumItems];


for (var i = 0; i < values.Length; i++)

values[i] = ...
class Vector2Comparer : IComparer

{

public int Compare(object x, object y)

{

var v1 = (Vector2) x;

var v2 = (Vector2)...
Instruments
class Vector2Comparer_v2 : IComparer<Vector2>

{

public int Compare(Vector2 v1, Vector2 v2)

{

var mag1 = v1.Magnitude()...
Interface - iPod 4G
0s
10s
20s
30s
40s
IComparer IComparer<T>
IL2CPP
static int CompareVector2 (Vector2 v1, Vector2 v2)

{

var mag1 = v1.Magnitude();

var mag2 = v2.Magnitude();



if (mag1 ...
static int CompareVector2_v2(Vector2 v1, Vector2 v2)

{

var mag1 = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);

var mag2 = Math...
Delegate Optimization? - iPod 4G
0s
2s
4s
6s
8s
Method Call Inline
IL2CPP
static int CompareVector2_v2(Vector2 v1, Vector2 v2)

{

var mag1 = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);

var mag2 = Math...
static int CompareVector2_v2(Vector2 v1, Vector2 v2)

{

var mag1 = (float)Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);

var mag2...
Delegate - iPod 4G
0s
2s
4s
6s
8s
Method Call Inline Inline Fixed
IL2CPP
static int CompareVector2_v3(Vector2 v1, Vector2 v2)

{

var mag1 = v1.X * v1.X + v1.Y * v1.Y;

var mag2 = v2.X * v2.X + v...
Delegate - iPod 4G
0s
1.5s
3s
4.5s
6s
Method Call Inline No Sqrt
IL2CPP
Vector2 Sort by Magnitude - iPod 4G
0s
35s
70s
105s
140s
IComparable IComparable<T> Delegate 1 Delegate 2 Delegate 3
Unity...
Two More Things
Fast and Unsafe
public float Magnitude()

{

Debug.Log ("Let's slow things down!");

return (float)Math.Sqrt(X*X + Y*Y);

}

One Time Init...
public float Magnitude()

{

Debug.Log ("Let's slow things down!");

return (float)Math.Sqrt(X*X + Y*Y);

}

// Generated ...
Thank you!
@jon_cham
@petersonjm1
Questions?
IL2CPP: Debugging and Profiling
IL2CPP: Debugging and Profiling
Nächste SlideShare
Wird geladen in …5
×

IL2CPP: Debugging and Profiling

1.347 Aufrufe

Veröffentlicht am

Gain a deeper understanding of how to debug and profile your content running with IL2CPP. In depth examples demonstrate how to diagnose problems and improve performance.

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

IL2CPP: Debugging and Profiling

  1. 1. IL2CPP: Profiling and Debugging Jonathan Chambers and Josh Peterson
  2. 2. Agenda
  3. 3. The Abridged Version IL2CPP
  4. 4. Where is IL2CPP?
  5. 5. Creating IL2CPP
  6. 6. How do we make IL2CPP?
  7. 7. Fundamental principle: Test first • Unit tests - C++ and C# (~500) • Integration tests (~2000) • Platform integration tests (~1000) Code conversion (il2cpp.exe) - C# Runtime (libil2cpp) - C++ How do we make IL2CPP?
  8. 8. Tools we use
  9. 9. • We debug with an IL2CPP standalone player • We check build time and size against real projects Internal tools
  10. 10. Internal organization of libil2cpp code Internal Calls Generated Code PALVM iOS Windows Other Platform
  11. 11. Our goal: move fast Photo credit: Alvesgaspar (CC BY-SA 3.0)
  12. 12. Debugging script code with IL2CPP
  13. 13. Best option: Debug code in the editor Acceptable option: Debug on device with Mono backend Debugging script code with IL2CPP Most fun option: Debug the generated C++ code!
  14. 14. When to debug generated C++ code An exception occurs only on the device Marshaling Interaction with native code
  15. 15. Deep dive: Debugging a managed exception in generated C++ code
  16. 16. • The converted code is the IL code, not C# code • Filter underscore characters from names • Sanity check often • Understand managed type layouts in native code Principles for debugging generated code
  17. 17. • Debugging generated C++ code is probably not a technique to use often. • Generated code will change in newer versions. • Generated C++ code can give Xcode problems. Caveats But for certain situations, this is a great skill to use!
  18. 18. Check out our IL2CPP Internals blog series! Debugging tips for generated code - http:// blogs.unity3d.com/2015/05/20/il2cpp-internals- debugging-tips-for-generated-code/ More information
  19. 19. Performance and Profiling
  20. 20. We make things fast for you! The Good News
  21. 21. Make it small and make it fast! Speed *and* Size
  22. 22. Make your code fast in general .Net Profiler
  23. 23. Make your code fast in Unity Unity Profiler
  24. 24. Make your code fast on device Native Profiler
  25. 25. var md5 = MD5.Create();
 var values = new byte[1024*1024];
 var random = new Random(100);
 random.NextBytes(values);
 
 TimeAction (() => md5.ComputeHash(values));
 Example
  26. 26. MD5 Hash 0ms 25ms 50ms 75ms 100ms iPod 4G Unity Mono IL2CPP
  27. 27. MD5 Hash 0ms 25ms 50ms 75ms 100ms iPod 4G iPhone 6 Unity Mono IL2CPP
  28. 28. struct Vector2
 {
 public float X;
 public float Y;
 
 public Vector2(float x, float y)
 {
 X = x;
 Y = x;
 }
 
 public float Magnitude()
 {
 return (float)Math.Sqrt(X*X + Y*Y);
 }
 }
 Example 2
  29. 29. const int kNumItems = 1000000;
 var vals = new Vector2[kNumItems]; 
 for (var i = 0; i < values.Length; i++)
 values[i] = new Vector2(i, values.Length - i); 
 TimeAction (() => Array.Sort (vals, new Vector2Comparer ()));
 Example 2 - cont’d
  30. 30. class Vector2Comparer : IComparer
 {
 public int Compare(object x, object y)
 {
 var v1 = (Vector2) x;
 var v2 = (Vector2) y;
 var mag1 = v1.Magnitude();
 var mag2 = v2.Magnitude();
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 } IComparer
  31. 31. Instruments
  32. 32. class Vector2Comparer_v2 : IComparer<Vector2>
 {
 public int Compare(Vector2 v1, Vector2 v2)
 {
 var mag1 = v1.Magnitude();
 var mag2 = v2.Magnitude();
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 } IComparer<T>
  33. 33. Interface - iPod 4G 0s 10s 20s 30s 40s IComparer IComparer<T> IL2CPP
  34. 34. static int CompareVector2 (Vector2 v1, Vector2 v2)
 {
 var mag1 = v1.Magnitude();
 var mag2 = v2.Magnitude();
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 Delegate v1
  35. 35. static int CompareVector2_v2(Vector2 v1, Vector2 v2)
 {
 var mag1 = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);
 var mag2 = Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y);
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 Delegate v2
  36. 36. Delegate Optimization? - iPod 4G 0s 2s 4s 6s 8s Method Call Inline IL2CPP
  37. 37. static int CompareVector2_v2(Vector2 v1, Vector2 v2)
 {
 var mag1 = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);
 var mag2 = Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y);
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 // Our function we inlined public float Magnitude()
 {
 return (float)Math.Sqrt(X*X + Y*Y);
 } Delegate v2 - What’s going on?
  38. 38. static int CompareVector2_v2(Vector2 v1, Vector2 v2)
 {
 var mag1 = (float)Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);
 var mag2 = (float)Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y);
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 Delegate v2 - Corrected
  39. 39. Delegate - iPod 4G 0s 2s 4s 6s 8s Method Call Inline Inline Fixed IL2CPP
  40. 40. static int CompareVector2_v3(Vector2 v1, Vector2 v2)
 {
 var mag1 = v1.X * v1.X + v1.Y * v1.Y;
 var mag2 = v2.X * v2.X + v2.Y * v2.Y;
 
 if (mag1 > mag2) return 1;
 
 if (mag1 < mag2) return -1;
 
 return 0;
 }
 Delegate v3
  41. 41. Delegate - iPod 4G 0s 1.5s 3s 4.5s 6s Method Call Inline No Sqrt IL2CPP
  42. 42. Vector2 Sort by Magnitude - iPod 4G 0s 35s 70s 105s 140s IComparable IComparable<T> Delegate 1 Delegate 2 Delegate 3 Unity Mono IL2CPP
  43. 43. Two More Things
  44. 44. Fast and Unsafe
  45. 45. public float Magnitude()
 {
 Debug.Log ("Let's slow things down!");
 return (float)Math.Sqrt(X*X + Y*Y);
 }
 One Time Initialization
  46. 46. public float Magnitude()
 {
 Debug.Log ("Let's slow things down!");
 return (float)Math.Sqrt(X*X + Y*Y);
 }
 // Generated C++ prologue static bool s_Il2CppMethodIntialized; if (!s_Il2CppMethodIntialized) { _stringLiteral0 = il2cpp_codegen_string_literal_from_index(0); s_Il2CppMethodIntialized = true; } One Time Initialization
  47. 47. Thank you!
  48. 48. @jon_cham @petersonjm1 Questions?

×