Performance is a feature! - London .NET User Group

Performance is a Feature!
Performance is a Feature!
Matt Warren
ca.com/apm
mattwarren.github.io
@matthewwarren
Performance is a feature! - London .NET User Group
Front-end
Database & Caching
.NET CLR
Mechanical
Sympathy
Why does performance matter?
What do we need to measure?
How we can fix the issues?
Why?
Save money
Save power
Bad perf == broken
Lost customers
Half a second delay caused
a 20% drop in traffic
(Google)
Why?
“The most amazing achievement of
the computer software industry is its
continuing cancellation of the steady
and staggering gains made by the
computer hardware industry.”
- Henry Peteroski
Why?
“We should forget about small efficiencies,
say about 97% of the time: premature
optimization is the root of all evil. Yet we
should not pass up our opportunities in
that critical 3%.“
- Donald Knuth
Never give up your
performance accidentally
Rico Mariani,
Performance Architect @
Microsoft
What?
Averages
are bad
Performance is a feature! - London .NET User Group
"most people have
more than the average
number of legs"
- Hans Rosling
Performance is a feature! - London .NET User Group
Performance is a feature! - London .NET User Group
https://blogs.msdn.microsoft.com/bharry/2016/03/28/introducing-application-analytics/
Application Insights Analytics
When?
In production
You won't see ANY perf issues
during unit tests
You won't see ALL perf issues
in Development
How?
Measure, measure, measure
1. Identify bottlenecks
2. Verify the optimisation works
How?
“The simple act of putting a render time in the upper right hand corner of every
page we serve forced us to fix all our performance regressions and omissions.”
How?
https://github.com/opserver/Opserver
How?
https://github.com/opserver/Opserver
How?
Micro-benchmarks
How?
Profiling -> Micro-benchmarks
Performance is a feature! - London .NET User Group
http://www.hanselman.com/blog/BenchmarkingNETCode.aspx
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
static Uri @object = new Uri("http://google.com/search");
[Benchmark(Baseline = true)]
public string RegularPropertyCall()
{
return @object.Host;
}
[Benchmark]
public object Reflection()
{
Type @class = @object.GetType();
PropertyInfo property =
@class.GetProperty(propertyName, bindingFlags);
return property.GetValue(@object);
}
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<Program>();
}
Compared to one second
• Millisecond – ms
–thousandth (0.001 or 1/1000)
• Microsecond - μs
–millionth (0.000001 or 1/1,000,000)
• Nanosecond - ns
–billionth (0.000000001 or 1/1,000,000,000)
BenchmarkDotNet
BenchmarkDotNet=v0.9.4.0
OS=Microsoft Windows NT 6.1.7601 Service Pack 1
Processor=Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, ProcessorCount=8
HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE
JitModules=clrjit-v4.6.100.0
Type=Program Mode=Throughput
Method | Median | StdDev | Scaled |
--------------------- |------------ |----------- |------- |
RegularPropertyCall |
Reflection |
BenchmarkDotNet
BenchmarkDotNet=v0.9.4.0
OS=Microsoft Windows NT 6.1.7601 Service Pack 1
Processor=Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, ProcessorCount=8
HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE
JitModules=clrjit-v4.6.100.0
Type=Program Mode=Throughput
Method | Median | StdDev | Scaled |
--------------------- |------------ |----------- |------- |
RegularPropertyCall | 13.4053 ns | 1.5826 ns | 1.00 |
Reflection | 232.7240 ns | 32.0018 ns | 17.36 |
[Params(1, 2, 3, 4, 5, 10, 100, 1000)]
public int Loops;
[Benchmark]
public string StringConcat()
{
string result = string.Empty;
for (int i = 0; i < Loops; ++i)
result = string.Concat(result, i.ToString());
return result;
}
[Benchmark]
public string StringBuilder()
{
StringBuilder sb = new StringBuilder(string.Empty);
for (int i = 0; i < Loops; ++i)
sb.Append(i.ToString());
return sb.ToString();
}
Performance is a feature! - London .NET User Group
Performance is a feature! - London .NET User Group
How?
Garbage Collection (GC)
Allocations are cheap, but cleaning up isn’t
Difficult to measure the impact of GC
Performance is a feature! - London .NET User Group
Performance is a feature! - London .NET User Group
https://samsaffron.com/archive/2011/10/28/in-managed-code-we-trust-our-
recent-battles-with-the-net-garbage-collector
Stack Overflow Performance Lessons
Use static classes
Don’t be afraid to write your own tools
Dapper, Jil, MiniProfiler,
Intimately know your platform - CLR
Roslyn Performance Lessons 1
public class Logger
{
public static void WriteLine(string s) { /*...*/ }
}
public class Logger
{
public void Log(int id, int size)
{
var s = string.Format("{0}:{1}", id, size);
Logger.WriteLine(s);
}
}
Essential Truths Everyone Should Know about Performance in a Large Managed Codebase
Roslyn Performance Lessons 1
public class Logger
{
public static void WriteLine(string s) { /*...*/ }
}
public class BoxingExample
{
public void Log(int id, int size)
{
var s = string.Format("{0}:{1}",
id.ToString(), size.ToString());
Logger.WriteLine(s);
}
}
AVOID BOXING
Roslyn Performance Lessons 2
class Symbol {
public string Name { get; private set; }
/*...*/
}
class Compiler {
private List<Symbol> symbols;
public Symbol FindMatchingSymbol(string name)
{
return symbols.FirstOrDefault(s => s.Name == name);
}
}
Roslyn Performance Lessons 2
class Symbol {
public string Name { get; private set; }
/*...*/
}
class Compiler {
private List<Symbol> symbols;
public Symbol FindMatchingSymbol(string name)
{
foreach (Symbol s in symbols)
{
if (s.Name == name)
return s;
}
return null;
}
}
DON’T USE LINQ
BenchmarkDotNet
BenchmarkDotNet=v0.9.4.0
OS=Microsoft Windows NT 6.1.7601 Service Pack 1
Processor=Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, ProcessorCount=8
Frequency=2630654 ticks, Resolution=380.1336 ns, Timer=TSC
HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE
JitModules=clrjit-v4.6.100.0
Type=Program Mode=Throughput Runtime=Clr
Method | Median | StdDev | Gen 0 | Bytes Allocated/Op |
---------- |----------- |---------- |------- |------------------- |
Iterative | 39.0957 ns | 0.2150 ns | - | 0.00 |
LINQ | 53.2441 ns | 0.5385 ns | 701.50 | 23.21 |
Roslyn Performance Lessons 3
public class Example
{
// Constructs a name like "Foo<T1, T2, T3>"
public string GenerateFullTypeName(string name, int arity)
{
StringBuilder sb = new StringBuilder();
sb.Append(name);
if (arity != 0)
{
sb.Append("<");
for (int i = 1; i < arity; i++)
{
sb.Append('T'); sb.Append(i.ToString());
}
sb.Append('T'); sb.Append(arity.ToString());
}
return sb.ToString();
}
}
Roslyn Performance Lessons 3
public class Example
{
// Constructs a name like "Foo<T1, T2, T3>"
public string GenerateFullTypeName(string name, int arity)
{
StringBuilder sb = new AcquireBuilder();
sb.Append(name);
if (arity != 0)
{
sb.Append("<");
for (int i = 1; i < arity; i++)
{
sb.Append('T'); sb.Append(i.ToString());
}
sb.Append('T'); sb.Append(arity.ToString());
}
return GetStringAndReleaseBuilder(sb);
}
}
OBJECT POOLING
Roslyn Performance Lessons 3
[ThreadStatic]
private static StringBuilder cachedStringBuilder;
private static StringBuilder AcquireBuilder()
{
StringBuilder result = cachedStringBuilder;
if (result == null)
{
return new StringBuilder();
}
result.Clear();
cachedStringBuilder = null;
return result;
}
private static string GetStringAndReleaseBuilder(StringBuilder sb)
{
string result = sb.ToString();
cachedStringBuilder = sb;
return result;
}
Questions?
@matthewwarren
mattwarren.github.io
https://confocal.io/
Code: matt
1 of 45

Recommended

From 'dotnet run' to 'hello world' by
From 'dotnet run' to 'hello world'From 'dotnet run' to 'hello world'
From 'dotnet run' to 'hello world'Matt Warren
86.4K views40 slides
Performance is a feature! - Developer South Coast - part 2 by
Performance is a feature!  - Developer South Coast - part 2Performance is a feature!  - Developer South Coast - part 2
Performance is a feature! - Developer South Coast - part 2Matt Warren
674 views29 slides
Performance Wins with eBPF: Getting Started (2021) by
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Brendan Gregg
1.4K views30 slides
Linux Systems Performance 2016 by
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016Brendan Gregg
504.5K views72 slides
Embedded systems by
Embedded systems Embedded systems
Embedded systems Katy Anton
751 views50 slides
All you need to know about the JavaScript event loop by
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopSaša Tatar
981 views15 slides

More Related Content

What's hot

DevoxxPL: JRebel Under The Covers by
DevoxxPL: JRebel Under The CoversDevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The CoversSimon Maple
1.2K views54 slides
Am I reading GC logs Correctly? by
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Tier1 App
2K views27 slides
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종 by
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종NAVER D2
4K views36 slides
Profiling & Testing with Spark by
Profiling & Testing with SparkProfiling & Testing with Spark
Profiling & Testing with SparkRoger Rafanell Mas
3K views51 slides
Systems@Scale 2021 BPF Performance Getting Started by
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedBrendan Gregg
1.5K views30 slides
LISA18: Hidden Linux Metrics with Prometheus eBPF Exporter by
LISA18: Hidden Linux Metrics with Prometheus eBPF ExporterLISA18: Hidden Linux Metrics with Prometheus eBPF Exporter
LISA18: Hidden Linux Metrics with Prometheus eBPF ExporterIvan Babrou
910 views57 slides

What's hot(20)

DevoxxPL: JRebel Under The Covers by Simon Maple
DevoxxPL: JRebel Under The CoversDevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The Covers
Simon Maple1.2K views
Am I reading GC logs Correctly? by Tier1 App
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
Tier1 App2K views
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종 by NAVER D2
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종
[2C1] 아파치 피그를 위한 테즈 연산 엔진 개발하기 최종
NAVER D24K views
Systems@Scale 2021 BPF Performance Getting Started by Brendan Gregg
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting Started
Brendan Gregg1.5K views
LISA18: Hidden Linux Metrics with Prometheus eBPF Exporter by Ivan Babrou
LISA18: Hidden Linux Metrics with Prometheus eBPF ExporterLISA18: Hidden Linux Metrics with Prometheus eBPF Exporter
LISA18: Hidden Linux Metrics with Prometheus eBPF Exporter
Ivan Babrou910 views
Is your profiler speaking the same language as you? -- Docklands JUG by Simon Maple
Is your profiler speaking the same language as you? -- Docklands JUGIs your profiler speaking the same language as you? -- Docklands JUG
Is your profiler speaking the same language as you? -- Docklands JUG
Simon Maple563 views
LISA17 Container Performance Analysis by Brendan Gregg
LISA17 Container Performance AnalysisLISA17 Container Performance Analysis
LISA17 Container Performance Analysis
Brendan Gregg9.3K views
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ... by Anne Nicolas
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Kernel Recipes 2018 - KernelShark 1.0; What's new and what's coming - Steven ...
Anne Nicolas2.2K views
Monitoring with Graylog - a modern approach to monitoring? by inovex GmbH
Monitoring with Graylog - a modern approach to monitoring?Monitoring with Graylog - a modern approach to monitoring?
Monitoring with Graylog - a modern approach to monitoring?
inovex GmbH8.9K views
Blazing Performance with Flame Graphs by Brendan Gregg
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
Brendan Gregg323.6K views
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck... by Ontico
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Ontico917 views
Don’t block the event loop! by hujinpu
Don’t block the event loop!Don’t block the event loop!
Don’t block the event loop!
hujinpu1.8K views
Deep dive into PostgreSQL statistics. by Alexey Lesovsky
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
Alexey Lesovsky10.4K views
Container Performance Analysis by Brendan Gregg
Container Performance AnalysisContainer Performance Analysis
Container Performance Analysis
Brendan Gregg448.6K views
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели... by Ontico
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Ontico3.2K views
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016 by Zabbix
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Zabbix1.5K views
OSSNA 2017 Performance Analysis Superpowers with Linux BPF by Brendan Gregg
OSSNA 2017 Performance Analysis Superpowers with Linux BPFOSSNA 2017 Performance Analysis Superpowers with Linux BPF
OSSNA 2017 Performance Analysis Superpowers with Linux BPF
Brendan Gregg5.1K views

Viewers also liked

рентабельный код by
рентабельный кодрентабельный код
рентабельный кодMax Arshinov
43.4K views18 slides
Framework Entities - Dissertação by
Framework Entities - DissertaçãoFramework Entities - Dissertação
Framework Entities - DissertaçãoMarcius Brandão
5.4K views145 slides
Framework Entities na CBSoft by
Framework Entities na CBSoftFramework Entities na CBSoft
Framework Entities na CBSoftMarcius Brandão
4K views6 slides
Aknop irigasi by
Aknop irigasiAknop irigasi
Aknop irigasiNendar DerDor
3.9K views3 slides
Where the wild things are - Benchmarking and Micro-Optimisations by
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsMatt Warren
1.5K views47 slides
Introduction to Docker by Adrian Mouat by
Introduction to Docker by Adrian MouatIntroduction to Docker by Adrian Mouat
Introduction to Docker by Adrian MouatContainer Solutions
7.4K views29 slides

Viewers also liked(19)

рентабельный код by Max Arshinov
рентабельный кодрентабельный код
рентабельный код
Max Arshinov43.4K views
Framework Entities - Dissertação by Marcius Brandão
Framework Entities - DissertaçãoFramework Entities - Dissertação
Framework Entities - Dissertação
Marcius Brandão5.4K views
Where the wild things are - Benchmarking and Micro-Optimisations by Matt Warren
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-Optimisations
Matt Warren1.5K views
有了 Agile,為什麼還要有 DevOps? by William Yeh
有了 Agile,為什麼還要有 DevOps?有了 Agile,為什麼還要有 DevOps?
有了 Agile,為什麼還要有 DevOps?
William Yeh12K views
Protecting Your APIs Against Attack & Hijack by CA API Management
Protecting Your APIs Against Attack & Hijack Protecting Your APIs Against Attack & Hijack
Protecting Your APIs Against Attack & Hijack
CA API Management18.4K views
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012 by devCAT Studio, NEXON
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
조정훈, 게임 프로그래머를 위한 클래스 설계, NDC2012
devCAT Studio, NEXON16.1K views
취미로 엔진 만들기 by Jiho Choi
취미로 엔진 만들기취미로 엔진 만들기
취미로 엔진 만들기
Jiho Choi16.2K views
Optimizing unity games (Google IO 2014) by Alexander Dolbilov
Optimizing unity games (Google IO 2014)Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)
Alexander Dolbilov39.1K views
C#을 사용한 빠른 툴 개발 by 흥배 최
C#을 사용한 빠른 툴 개발C#을 사용한 빠른 툴 개발
C#을 사용한 빠른 툴 개발
흥배 최6.5K views
게임 프레임워크의 아키텍쳐와 디자인 패턴 by MinGeun Park
게임 프레임워크의 아키텍쳐와 디자인 패턴게임 프레임워크의 아키텍쳐와 디자인 패턴
게임 프레임워크의 아키텍쳐와 디자인 패턴
MinGeun Park13.7K views
게임 개발에 자주 사용되는 디자인 패턴 by 예림 임
게임 개발에 자주 사용되는 디자인 패턴게임 개발에 자주 사용되는 디자인 패턴
게임 개발에 자주 사용되는 디자인 패턴
예림 임20.7K views
DataStax: Spark Cassandra Connector - Past, Present and Future by DataStax Academy
DataStax: Spark Cassandra Connector - Past, Present and FutureDataStax: Spark Cassandra Connector - Past, Present and Future
DataStax: Spark Cassandra Connector - Past, Present and Future
DataStax Academy3.4K views
用十分鐘開始理解深度學習技術 (從 dnn.js 專案出發) by 鍾誠 陳鍾誠
用十分鐘開始理解深度學習技術  (從 dnn.js 專案出發)用十分鐘開始理解深度學習技術  (從 dnn.js 專案出發)
用十分鐘開始理解深度學習技術 (從 dnn.js 專案出發)
鍾誠 陳鍾誠12.3K views
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear by Kevin Griffin
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High GearASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
Kevin Griffin1.5K views
C#으로 게임 엔진 만들기(1) by 지환 김
C#으로 게임 엔진 만들기(1)C#으로 게임 엔진 만들기(1)
C#으로 게임 엔진 만들기(1)
지환 김5.6K views
10 performance and scalability secrets of ASP.NET websites by oazabir
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites
oazabir120.6K views

Similar to Performance is a feature! - London .NET User Group

Performance and how to measure it - ProgSCon London 2016 by
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Matt Warren
769 views41 slides
Performance is a Feature! at DDD 11 by
Performance is a Feature! at DDD 11Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Matt Warren
1.7K views49 slides
Performance is a Feature! by
Performance is a Feature!Performance is a Feature!
Performance is a Feature!PostSharp Technologies
835 views53 slides
Exploring the Final Frontier of Data Center Orchestration: Network Elements -... by
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Puppet
2.2K views27 slides
Programar para GPUs by
Programar para GPUsProgramar para GPUs
Programar para GPUsAlcides Fonseca
280 views26 slides
Better Network Management Through Network Programmability by
Better Network Management Through Network ProgrammabilityBetter Network Management Through Network Programmability
Better Network Management Through Network ProgrammabilityCisco Canada
4.4K views82 slides

Similar to Performance is a feature! - London .NET User Group(20)

Performance and how to measure it - ProgSCon London 2016 by Matt Warren
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016
Matt Warren769 views
Performance is a Feature! at DDD 11 by Matt Warren
Performance is a Feature! at DDD 11Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11
Matt Warren1.7K views
Exploring the Final Frontier of Data Center Orchestration: Network Elements -... by Puppet
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Puppet2.2K views
Better Network Management Through Network Programmability by Cisco Canada
Better Network Management Through Network ProgrammabilityBetter Network Management Through Network Programmability
Better Network Management Through Network Programmability
Cisco Canada4.4K views
មេរៀនៈ Data Structure and Algorithm in C/C++ by Ngeam Soly
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
Ngeam Soly22.3K views
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches by Marina Kolpakova
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Marina Kolpakova1.3K views
Intelligent Monitoring by Intelie
Intelligent MonitoringIntelligent Monitoring
Intelligent Monitoring
Intelie2.4K views
Hierarchical free monads and software design in fp by Alexander Granin
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
Alexander Granin161 views
Expanding your impact with programmability in the data center by Cisco Canada
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data center
Cisco Canada348 views
MCSoC'13 Keynote Talk "Taming Big Data Streams" by Hideyuki Kawashima
MCSoC'13 Keynote Talk "Taming Big Data Streams"MCSoC'13 Keynote Talk "Taming Big Data Streams"
MCSoC'13 Keynote Talk "Taming Big Data Streams"
Hideyuki Kawashima824 views
HandlerSocket plugin for MySQL (English) by akirahiguchi
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
akirahiguchi9.5K views
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법 by GangSeok Lee
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
GangSeok Lee2.5K views
External Language Stored Procedures for MySQL by Antony T Curtis
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
Antony T Curtis3.9K views
RTOS implementation by Rajan Kumar
RTOS implementationRTOS implementation
RTOS implementation
Rajan Kumar814 views
BPF: Tracing and more by Brendan Gregg
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
Brendan Gregg200.3K views

Recently uploaded

Chat GPTs by
Chat GPTsChat GPTs
Chat GPTsGene Leybzon
17 views36 slides
Winter Projects GDSC IITK by
Winter Projects GDSC IITKWinter Projects GDSC IITK
Winter Projects GDSC IITKSahilSingh368445
511 views60 slides
aATP - New Correlation Confirmation Feature.pptx by
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptxEsatEsenek1
225 views6 slides
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...NimaTorabi2
19 views17 slides
Top-5-production-devconMunich-2023-v2.pptx by
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptxTier1 app
9 views42 slides
Transport Management System - Shipment & Container Tracking by
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container TrackingFreightoscope
6 views3 slides

Recently uploaded(20)

aATP - New Correlation Confirmation Feature.pptx by EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1225 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi219 views
Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 views
Transport Management System - Shipment & Container Tracking by Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views
Google Solutions Challenge 2024 Talk pdf by MohdAbdulAleem4
Google Solutions Challenge 2024 Talk pdfGoogle Solutions Challenge 2024 Talk pdf
Google Solutions Challenge 2024 Talk pdf
MohdAbdulAleem447 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67026 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert37 views
Streamlining Your Business Operations with Enterprise Application Integration... by Flexsin
Streamlining Your Business Operations with Enterprise Application Integration...Streamlining Your Business Operations with Enterprise Application Integration...
Streamlining Your Business Operations with Enterprise Application Integration...
Flexsin 5 views
predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app10 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic17 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom18 views

Performance is a feature! - London .NET User Group

  • 1. Performance is a Feature!
  • 2. Performance is a Feature! Matt Warren ca.com/apm mattwarren.github.io @matthewwarren
  • 4. Front-end Database & Caching .NET CLR Mechanical Sympathy
  • 5. Why does performance matter? What do we need to measure? How we can fix the issues?
  • 6. Why? Save money Save power Bad perf == broken Lost customers Half a second delay caused a 20% drop in traffic (Google)
  • 7. Why? “The most amazing achievement of the computer software industry is its continuing cancellation of the steady and staggering gains made by the computer hardware industry.” - Henry Peteroski
  • 8. Why? “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.“ - Donald Knuth
  • 9. Never give up your performance accidentally Rico Mariani, Performance Architect @ Microsoft
  • 12. "most people have more than the average number of legs" - Hans Rosling
  • 16. When? In production You won't see ANY perf issues during unit tests You won't see ALL perf issues in Development
  • 17. How? Measure, measure, measure 1. Identify bottlenecks 2. Verify the optimisation works
  • 18. How? “The simple act of putting a render time in the upper right hand corner of every page we serve forced us to fix all our performance regressions and omissions.”
  • 25. using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; static Uri @object = new Uri("http://google.com/search"); [Benchmark(Baseline = true)] public string RegularPropertyCall() { return @object.Host; } [Benchmark] public object Reflection() { Type @class = @object.GetType(); PropertyInfo property = @class.GetProperty(propertyName, bindingFlags); return property.GetValue(@object); } static void Main(string[] args) { var summary = BenchmarkRunner.Run<Program>(); }
  • 26. Compared to one second • Millisecond – ms –thousandth (0.001 or 1/1000) • Microsecond - μs –millionth (0.000001 or 1/1,000,000) • Nanosecond - ns –billionth (0.000000001 or 1/1,000,000,000)
  • 27. BenchmarkDotNet BenchmarkDotNet=v0.9.4.0 OS=Microsoft Windows NT 6.1.7601 Service Pack 1 Processor=Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, ProcessorCount=8 HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE JitModules=clrjit-v4.6.100.0 Type=Program Mode=Throughput Method | Median | StdDev | Scaled | --------------------- |------------ |----------- |------- | RegularPropertyCall | Reflection |
  • 28. BenchmarkDotNet BenchmarkDotNet=v0.9.4.0 OS=Microsoft Windows NT 6.1.7601 Service Pack 1 Processor=Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, ProcessorCount=8 HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE JitModules=clrjit-v4.6.100.0 Type=Program Mode=Throughput Method | Median | StdDev | Scaled | --------------------- |------------ |----------- |------- | RegularPropertyCall | 13.4053 ns | 1.5826 ns | 1.00 | Reflection | 232.7240 ns | 32.0018 ns | 17.36 |
  • 29. [Params(1, 2, 3, 4, 5, 10, 100, 1000)] public int Loops; [Benchmark] public string StringConcat() { string result = string.Empty; for (int i = 0; i < Loops; ++i) result = string.Concat(result, i.ToString()); return result; } [Benchmark] public string StringBuilder() { StringBuilder sb = new StringBuilder(string.Empty); for (int i = 0; i < Loops; ++i) sb.Append(i.ToString()); return sb.ToString(); }
  • 32. How? Garbage Collection (GC) Allocations are cheap, but cleaning up isn’t Difficult to measure the impact of GC
  • 36. Stack Overflow Performance Lessons Use static classes Don’t be afraid to write your own tools Dapper, Jil, MiniProfiler, Intimately know your platform - CLR
  • 37. Roslyn Performance Lessons 1 public class Logger { public static void WriteLine(string s) { /*...*/ } } public class Logger { public void Log(int id, int size) { var s = string.Format("{0}:{1}", id, size); Logger.WriteLine(s); } } Essential Truths Everyone Should Know about Performance in a Large Managed Codebase
  • 38. Roslyn Performance Lessons 1 public class Logger { public static void WriteLine(string s) { /*...*/ } } public class BoxingExample { public void Log(int id, int size) { var s = string.Format("{0}:{1}", id.ToString(), size.ToString()); Logger.WriteLine(s); } } AVOID BOXING
  • 39. Roslyn Performance Lessons 2 class Symbol { public string Name { get; private set; } /*...*/ } class Compiler { private List<Symbol> symbols; public Symbol FindMatchingSymbol(string name) { return symbols.FirstOrDefault(s => s.Name == name); } }
  • 40. Roslyn Performance Lessons 2 class Symbol { public string Name { get; private set; } /*...*/ } class Compiler { private List<Symbol> symbols; public Symbol FindMatchingSymbol(string name) { foreach (Symbol s in symbols) { if (s.Name == name) return s; } return null; } } DON’T USE LINQ
  • 41. BenchmarkDotNet BenchmarkDotNet=v0.9.4.0 OS=Microsoft Windows NT 6.1.7601 Service Pack 1 Processor=Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, ProcessorCount=8 Frequency=2630654 ticks, Resolution=380.1336 ns, Timer=TSC HostCLR=MS.NET 4.0.30319.42000, Arch=32-bit RELEASE JitModules=clrjit-v4.6.100.0 Type=Program Mode=Throughput Runtime=Clr Method | Median | StdDev | Gen 0 | Bytes Allocated/Op | ---------- |----------- |---------- |------- |------------------- | Iterative | 39.0957 ns | 0.2150 ns | - | 0.00 | LINQ | 53.2441 ns | 0.5385 ns | 701.50 | 23.21 |
  • 42. Roslyn Performance Lessons 3 public class Example { // Constructs a name like "Foo<T1, T2, T3>" public string GenerateFullTypeName(string name, int arity) { StringBuilder sb = new StringBuilder(); sb.Append(name); if (arity != 0) { sb.Append("<"); for (int i = 1; i < arity; i++) { sb.Append('T'); sb.Append(i.ToString()); } sb.Append('T'); sb.Append(arity.ToString()); } return sb.ToString(); } }
  • 43. Roslyn Performance Lessons 3 public class Example { // Constructs a name like "Foo<T1, T2, T3>" public string GenerateFullTypeName(string name, int arity) { StringBuilder sb = new AcquireBuilder(); sb.Append(name); if (arity != 0) { sb.Append("<"); for (int i = 1; i < arity; i++) { sb.Append('T'); sb.Append(i.ToString()); } sb.Append('T'); sb.Append(arity.ToString()); } return GetStringAndReleaseBuilder(sb); } } OBJECT POOLING
  • 44. Roslyn Performance Lessons 3 [ThreadStatic] private static StringBuilder cachedStringBuilder; private static StringBuilder AcquireBuilder() { StringBuilder result = cachedStringBuilder; if (result == null) { return new StringBuilder(); } result.Clear(); cachedStringBuilder = null; return result; } private static string GetStringAndReleaseBuilder(StringBuilder sb) { string result = sb.ToString(); cachedStringBuilder = sb; return result; }