SlideShare a Scribd company logo
• Motivation
• Identifying memory traffic problems
• Specific code patterns
• General tips and tricks
• Memory allocations are cheap
• But not free
• And have side effects
• Don’t forget to think about the memory
Step I
Identification
• Provide numeric performance information about the
system
• Located in different areas in the system - disk, .NET,
networking, OS objects
• Available on-demand using built-in tools like
perfmon and typeperf
• Can write your own but that’s not the topic of our
talk…
• High-speed logging framework supporting more
than 100K structured messages per second
• .NET, drivers, services, third party components
• Can be turned on on-demand while running
• Very small overhead
• Can write your own but that’s not the topic of our
talk…
perfview
Demo
public override void Write(char value)
{
FinalText += value;
}
• Static
• Dynamic profiling
Step II
Avoidance
Searching
Demo
struct Struct {
public int Value { get; set; }
}
struct StructWithSpecializedEquals {
public int Value { get; set; }
public override bool Equals(object obj) {
if (!(obj is StructWithSpecializedEquals)) return false;
return ((StructWithSpecializedEquals)obj).Value == Value;
}
}
struct StructEquatable : IEquatable<StructEquatable> {
public int Value { get; set; }
public bool Equals(StructEquatable other) {
return Value == other.Value;
}
}
private const int N = 10000;
…
structs = Enumerable.Range(0, N)
.Select(v => new Struct { Value = v })
.ToList();
structWithSpecializedEqualses = Enumerable.Range(0, N)
.Select(v => new StructWithSpecializedEquals { Value = v })
.ToList();
structEquatables = Enumerable.Range(0, N)
.Select(v => new StructEquatable { Value = v })
.ToList();
[Benchmark]
public bool SearchStruct() {
return structs.Contains(structs.Last());
}
[Benchmark]
public bool SearchStructWithSpecializedEquals() {
…
}
[Benchmark]
public bool SearchStructEquatable() {
…
}
Capturing
Demo
public void CaptureState() {
_globalSum = 0;
for (int i = 0; i < Elements; ++i) {
var data = new Data { Value = i };
TaskStub.StartNew(() => {
_globalSum += data.Value;
});
}
}
public void PassStateAsParameter() {
_globalSum = 0;
for (int i = 0; i < Elements; ++i) {
var data = new Data { Value = i };
TaskStub.StartNew(d => {
_globalSum += (d as Data).Value;
}, data);
}
}
public void NoCapturedState() {
_globalSum = 0;
for (int i = 0; i < Elements; ++i) {
TaskStub.StartNew(() => {
_globalSum += Data.Default.Value;
});
}
}
public void NoStateAndNoLambda() {
_globalSum = 0;
for (int i = 0; i < Elements; ++i) {
TaskStub.StartNew(AddFunction);
}
}
private static void AddFunction() {
_globalSum += Data.Default.Value;
}
LINQ
Demo
public static double CalculateWithLoops() {
int sum = 0;
for (int i = Minimum; i < Maximum; ++i) {
var digits = new int[10];
var number = i;
while (number > 0) {
digits[number % 10] += 1;
number /= 10;
}
for (int d = 0; d < digits.Length; ++d)
if (digits[d] == 1) // then this is a unique digit
++sum;
}
return (double)sum / (Maximum - Minimum);
}
public static double CalculateWithLoopsAndString() {
int sum = 0;
for (int i = Minimum; i < Maximum; ++i) {
var digits = new int[10];
var s = i.ToString();
for (var k = 0; k < s.Length; ++k)
digits[s[k] - '0'] += 1;
for (int d = 0; d < digits.Length; ++d)
if (digits[d] == 1) // then this is a unique digit
++sum;
}
return (double)sum / (Maximum - Minimum);
}
public static double CalculateWithLinq() {
return Enumerable.Range(Minimum, Maximum - Minimum)
.Select(i => i.ToString()
.AsEnumerable()
.GroupBy(
c => c,
c => c,
(k, g) => new {
Character = k,
Count = g.Count()
})
.Count(g => g.Count == 1))
.Average();
}
Step III
Diligence
• You have a large heap. Don’t make it worse by
frequent calls to full GC which is going to take a long
time.
• Instead, use what we learned to reduce memory
usage
• And don’t forget to remove debugging code from
production
• Value types (structs) have a compact memory layout,
and can be embedded in their parent object, making
cache’s life easier and generally reducing footprint
• Pool expensive or large objects instead of returning
them to GC
• For large arrays (e.g. byte[]) may use
System.Buffers
• Finalizers run at some point after the object is no
longer referenced by the application (non-
deterministic)
• Finalizers run on a separate thread and create
potential concurrency issues
• Finalization prolongs object lifetime and can create
leaks if finalizers don’t complete quickly enough
• Better to use deterministic resource management
(IDisposable)
• Although a single memory allocation is extremely
fast, it adds up
• All based on real questions, stories and bugs
• Don’t overcomplicate where it’s not needed
• Measure
• And optimize…
• DIY: https://github.com/dinazil/look-mommy-no-gc
Look Mommy, No GC! (TechDays NL 2017)

More Related Content

What's hot

Java & OOP Core Concept
Java & OOP Core ConceptJava & OOP Core Concept
Java & OOP Core Concept
Pin-Lun Huang
 
10 chapter6 heaps_priority_queues
10 chapter6 heaps_priority_queues10 chapter6 heaps_priority_queues
10 chapter6 heaps_priority_queues
SSE_AndyLi
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
Yulia Shcherbachova
 
The Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystemThe Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystem
inside-BigData.com
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
Jonathan Katz
 
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3SICEF
 
Cloud jpl
Cloud jplCloud jpl
Cloud jpl
Marc de Palol
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlers
InfluxData
 
Open XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand DechouxOpen XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand DechouxPublicis Sapient Engineering
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
Satalia
 
Survey onhpcs languages
Survey onhpcs languagesSurvey onhpcs languages
Survey onhpcs languages
Saliya Ekanayake
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvasdeanhudson
 
TensorFlow Object Detection API
TensorFlow Object Detection APITensorFlow Object Detection API
TensorFlow Object Detection API
Algoscale Technologies Inc.
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
Sasha Goldshtein
 
Dma
DmaDma
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
InfluxData
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5
Takao Wada
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020
InfluxData
 
Porting and optimizing UniFrac for GPUs
Porting and optimizing UniFrac for GPUsPorting and optimizing UniFrac for GPUs
Porting and optimizing UniFrac for GPUs
Igor Sfiligoi
 

What's hot (20)

Java & OOP Core Concept
Java & OOP Core ConceptJava & OOP Core Concept
Java & OOP Core Concept
 
10 chapter6 heaps_priority_queues
10 chapter6 heaps_priority_queues10 chapter6 heaps_priority_queues
10 chapter6 heaps_priority_queues
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
 
The Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystemThe Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystem
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
 
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
Webelinx - iOS development: earn 100k daily with 1h of coding #tnt3
 
Cloud jpl
Cloud jplCloud jpl
Cloud jpl
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlers
 
Open XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand DechouxOpen XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand Dechoux
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
 
Survey onhpcs languages
Survey onhpcs languagesSurvey onhpcs languages
Survey onhpcs languages
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvas
 
TensorFlow Object Detection API
TensorFlow Object Detection APITensorFlow Object Detection API
TensorFlow Object Detection API
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
 
Toy Model Overview
Toy Model OverviewToy Model Overview
Toy Model Overview
 
Dma
DmaDma
Dma
 
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020
 
Porting and optimizing UniFrac for GPUs
Porting and optimizing UniFrac for GPUsPorting and optimizing UniFrac for GPUs
Porting and optimizing UniFrac for GPUs
 

Similar to Look Mommy, No GC! (TechDays NL 2017)

Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"
Yulia Tsisyk
 
State of the .Net Performance
State of the .Net PerformanceState of the .Net Performance
State of the .Net Performance
CUSTIS
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
ssuser0c24d5
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
nilesh405711
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
YashpalYadav46
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
DevliNeeraj
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
Fwdays
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
ngonidzashemutsipa
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
PROIDEA
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Languagemspline
 
Node.js extensions in C++
Node.js extensions in C++Node.js extensions in C++
Node.js extensions in C++
Kenneth Geisshirt
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
saifnasir3
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
FarazKhan89093
 
Golang in TiDB (GopherChina 2017)
Golang in TiDB  (GopherChina 2017)Golang in TiDB  (GopherChina 2017)
Golang in TiDB (GopherChina 2017)
PingCAP
 
17javascript.ppt
17javascript.ppt17javascript.ppt
17javascript.ppt
PraveenRai90
 
17javascript.ppt
17javascript.ppt17javascript.ppt
17javascript.ppt
bcanawakadalcollege
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
Tara Hardin
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
Petr Dvorak
 

Similar to Look Mommy, No GC! (TechDays NL 2017) (20)

Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"
 
State of the .Net Performance
State of the .Net PerformanceState of the .Net Performance
State of the .Net Performance
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
Node.js extensions in C++
Node.js extensions in C++Node.js extensions in C++
Node.js extensions in C++
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
Oops concept
Oops conceptOops concept
Oops concept
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
 
Golang in TiDB (GopherChina 2017)
Golang in TiDB  (GopherChina 2017)Golang in TiDB  (GopherChina 2017)
Golang in TiDB (GopherChina 2017)
 
17javascript.ppt
17javascript.ppt17javascript.ppt
17javascript.ppt
 
17javascript.ppt
17javascript.ppt17javascript.ppt
17javascript.ppt
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 

More from Dina Goldshtein

How Does the Internet Work? (Wix she codes; branch)
How Does the Internet Work? (Wix she codes; branch)How Does the Internet Work? (Wix she codes; branch)
How Does the Internet Work? (Wix she codes; branch)
Dina Goldshtein
 
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Dina Goldshtein
 
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Dina Goldshtein
 
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
Dina Goldshtein
 
Look Mommy, no GC! (.NET Summit 2017)
Look Mommy, no GC! (.NET Summit 2017)Look Mommy, no GC! (.NET Summit 2017)
Look Mommy, no GC! (.NET Summit 2017)
Dina Goldshtein
 
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Dina Goldshtein
 
Look Mommy, no GC! (BrightSource)
Look Mommy, no GC! (BrightSource)Look Mommy, no GC! (BrightSource)
Look Mommy, no GC! (BrightSource)
Dina Goldshtein
 
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
Dina Goldshtein
 
Look Mommy, no GC! (SDP May 2017)
Look Mommy, no GC! (SDP May 2017)Look Mommy, no GC! (SDP May 2017)
Look Mommy, no GC! (SDP May 2017)
Dina Goldshtein
 
Look Mommy, No GC! (Codecamp Iasi 2017)
Look Mommy, No GC! (Codecamp Iasi 2017)Look Mommy, No GC! (Codecamp Iasi 2017)
Look Mommy, No GC! (Codecamp Iasi 2017)
Dina Goldshtein
 
Look Mommy, No GC! (NDC London 2017)
Look Mommy, No GC! (NDC London 2017)Look Mommy, No GC! (NDC London 2017)
Look Mommy, No GC! (NDC London 2017)
Dina Goldshtein
 
How does the Internet Work?
How does the Internet Work?How does the Internet Work?
How does the Internet Work?
Dina Goldshtein
 
How does the Internet Work?
How does the Internet Work?How does the Internet Work?
How does the Internet Work?
Dina Goldshtein
 
Things They Don’t Teach You @ School
Things They Don’t Teach You @ SchoolThings They Don’t Teach You @ School
Things They Don’t Teach You @ School
Dina Goldshtein
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
Dina Goldshtein
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
Dina Goldshtein
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Dina Goldshtein
 

More from Dina Goldshtein (17)

How Does the Internet Work? (Wix she codes; branch)
How Does the Internet Work? (Wix she codes; branch)How Does the Internet Work? (Wix she codes; branch)
How Does the Internet Work? (Wix she codes; branch)
 
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
Self-Aware Applications: Automatic Production Monitoring (SDP November 2017)
 
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
Self-Aware Applications: Automatic Production Monitoring (TechDays NL 2017)
 
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
ETW - Monitor Anything, Anytime, Anywhere (Velocity NYC 2017)
 
Look Mommy, no GC! (.NET Summit 2017)
Look Mommy, no GC! (.NET Summit 2017)Look Mommy, no GC! (.NET Summit 2017)
Look Mommy, no GC! (.NET Summit 2017)
 
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
Self-Aware Applications: Automatic Production Monitoring (NDC Sydney 2017)
 
Look Mommy, no GC! (BrightSource)
Look Mommy, no GC! (BrightSource)Look Mommy, no GC! (BrightSource)
Look Mommy, no GC! (BrightSource)
 
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
 
Look Mommy, no GC! (SDP May 2017)
Look Mommy, no GC! (SDP May 2017)Look Mommy, no GC! (SDP May 2017)
Look Mommy, no GC! (SDP May 2017)
 
Look Mommy, No GC! (Codecamp Iasi 2017)
Look Mommy, No GC! (Codecamp Iasi 2017)Look Mommy, No GC! (Codecamp Iasi 2017)
Look Mommy, No GC! (Codecamp Iasi 2017)
 
Look Mommy, No GC! (NDC London 2017)
Look Mommy, No GC! (NDC London 2017)Look Mommy, No GC! (NDC London 2017)
Look Mommy, No GC! (NDC London 2017)
 
How does the Internet Work?
How does the Internet Work?How does the Internet Work?
How does the Internet Work?
 
How does the Internet Work?
How does the Internet Work?How does the Internet Work?
How does the Internet Work?
 
Things They Don’t Teach You @ School
Things They Don’t Teach You @ SchoolThings They Don’t Teach You @ School
Things They Don’t Teach You @ School
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 

Recently uploaded

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

Look Mommy, No GC! (TechDays NL 2017)

  • 1.
  • 2.
  • 3. • Motivation • Identifying memory traffic problems • Specific code patterns • General tips and tricks
  • 4. • Memory allocations are cheap • But not free • And have side effects • Don’t forget to think about the memory
  • 5.
  • 6.
  • 8. • Provide numeric performance information about the system • Located in different areas in the system - disk, .NET, networking, OS objects • Available on-demand using built-in tools like perfmon and typeperf • Can write your own but that’s not the topic of our talk…
  • 9.
  • 10. • High-speed logging framework supporting more than 100K structured messages per second • .NET, drivers, services, third party components • Can be turned on on-demand while running • Very small overhead • Can write your own but that’s not the topic of our talk…
  • 12.
  • 13.
  • 14.
  • 15. public override void Write(char value) { FinalText += value; }
  • 18.
  • 20. struct Struct { public int Value { get; set; } }
  • 21. struct StructWithSpecializedEquals { public int Value { get; set; } public override bool Equals(object obj) { if (!(obj is StructWithSpecializedEquals)) return false; return ((StructWithSpecializedEquals)obj).Value == Value; } }
  • 22. struct StructEquatable : IEquatable<StructEquatable> { public int Value { get; set; } public bool Equals(StructEquatable other) { return Value == other.Value; } }
  • 23. private const int N = 10000; … structs = Enumerable.Range(0, N) .Select(v => new Struct { Value = v }) .ToList(); structWithSpecializedEqualses = Enumerable.Range(0, N) .Select(v => new StructWithSpecializedEquals { Value = v }) .ToList(); structEquatables = Enumerable.Range(0, N) .Select(v => new StructEquatable { Value = v }) .ToList();
  • 24. [Benchmark] public bool SearchStruct() { return structs.Contains(structs.Last()); } [Benchmark] public bool SearchStructWithSpecializedEquals() { … } [Benchmark] public bool SearchStructEquatable() { … }
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 35. public void CaptureState() { _globalSum = 0; for (int i = 0; i < Elements; ++i) { var data = new Data { Value = i }; TaskStub.StartNew(() => { _globalSum += data.Value; }); } }
  • 36. public void PassStateAsParameter() { _globalSum = 0; for (int i = 0; i < Elements; ++i) { var data = new Data { Value = i }; TaskStub.StartNew(d => { _globalSum += (d as Data).Value; }, data); } }
  • 37. public void NoCapturedState() { _globalSum = 0; for (int i = 0; i < Elements; ++i) { TaskStub.StartNew(() => { _globalSum += Data.Default.Value; }); } }
  • 38. public void NoStateAndNoLambda() { _globalSum = 0; for (int i = 0; i < Elements; ++i) { TaskStub.StartNew(AddFunction); } } private static void AddFunction() { _globalSum += Data.Default.Value; }
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 47. public static double CalculateWithLoops() { int sum = 0; for (int i = Minimum; i < Maximum; ++i) { var digits = new int[10]; var number = i; while (number > 0) { digits[number % 10] += 1; number /= 10; } for (int d = 0; d < digits.Length; ++d) if (digits[d] == 1) // then this is a unique digit ++sum; } return (double)sum / (Maximum - Minimum); }
  • 48. public static double CalculateWithLoopsAndString() { int sum = 0; for (int i = Minimum; i < Maximum; ++i) { var digits = new int[10]; var s = i.ToString(); for (var k = 0; k < s.Length; ++k) digits[s[k] - '0'] += 1; for (int d = 0; d < digits.Length; ++d) if (digits[d] == 1) // then this is a unique digit ++sum; } return (double)sum / (Maximum - Minimum); }
  • 49. public static double CalculateWithLinq() { return Enumerable.Range(Minimum, Maximum - Minimum) .Select(i => i.ToString() .AsEnumerable() .GroupBy( c => c, c => c, (k, g) => new { Character = k, Count = g.Count() }) .Count(g => g.Count == 1)) .Average(); }
  • 50.
  • 52. • You have a large heap. Don’t make it worse by frequent calls to full GC which is going to take a long time. • Instead, use what we learned to reduce memory usage • And don’t forget to remove debugging code from production
  • 53.
  • 54.
  • 55.
  • 56. • Value types (structs) have a compact memory layout, and can be embedded in their parent object, making cache’s life easier and generally reducing footprint
  • 57.
  • 58. • Pool expensive or large objects instead of returning them to GC • For large arrays (e.g. byte[]) may use System.Buffers
  • 59.
  • 60. • Finalizers run at some point after the object is no longer referenced by the application (non- deterministic) • Finalizers run on a separate thread and create potential concurrency issues • Finalization prolongs object lifetime and can create leaks if finalizers don’t complete quickly enough • Better to use deterministic resource management (IDisposable)
  • 61. • Although a single memory allocation is extremely fast, it adds up • All based on real questions, stories and bugs • Don’t overcomplicate where it’s not needed • Measure • And optimize… • DIY: https://github.com/dinazil/look-mommy-no-gc