SlideShare a Scribd company logo
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
Yevhen Tatarynov
Software developer with 15 years of experience in commercial
software and database development (.NET / MS SQL / Delphi)
PhD in math, specializing in the theoretical foundations of
computer science and cybernetics
I was involved in projects performing complex mathematical calculations and processing large
amounts of data. For now my role senior software developer in infrastructure team, Covent IT.
Point of professional interest:
application performance optimization and analysis
writing C# code similar in performance to C++
advanced debugging
Agenda
The first
challenge?
Measurements To much … ?
Summary
QA
The second
challenge?
Is It an
bottleneck?
Measurements
The first challenge?
Console .NET application
Read *.csv data files
Process data in
multiple threads
Write results in MS
Excel file
Use .NET Framework
4.6.2 Run on Windows It works correctly
Measurements
Measurement Tools
DotNetBenchmark
Visual Studio
Performance Profiler
Perfview R# dotTrace R# dotMemory
Performance
monitor
dotMemoryScreen
dotMemory Snapshot
dotTrace Snapshot
Too much…?
# Too many code issues?
Unused variables
Unused properties
Unused objects not allocated
Unused data not loaded from files
Unused fields don’t increase object
size
# Memory snapshot
Total memory old
Total memory new
Total memory diff
Percent
419,750 MB
359,971 MB
14 %
-55,599 MB
# Too many keys
ConcurrentDictionary<MyKey,string>
public struct MyKey
{
string field1;
string field2;
/*.....*/
}
Boxing
ConcurrentDictionary<TKey,TValue> classes have the same
functionality as the Hashtable class. A ConcurrentDictionary
<TKey,TValue> of a specific type (other than Object) provides
better performance than a Hashtable for value types.
This is because the elements of Hashtable are of type Object;
therefore, boxing and unboxing typically occur when you store
or retrieve a value type.
StackOverflow
Since you only override Equals and don’t implement
IEquatable<T>, the dictionary is forced to box one of the two
instances whenever it compares two of them for equality
because it's passing an instance into an
Equals-method-accepting object.
If you implement IEquatable<T>, then the dictionary can (and
will) use the version of Equals that accepts the parameter as a
T, which won't require boxing.
IEquatable interface
public struct MyKey : IEquatable<MyKey>
{
string field1;
string field2;
string field3;
/*.....*/
public bool Equals(MyKey other);
}
# Memory snapshot
Total memory old
Total memory new
Total memory diff
Percent
359,971 MB
137,294 MB
65 %
-251,654 MB
# Too much System.Double in heap?
class MyClass<T> where T : struct
{
T Add(T a, T b) =>
(dynamic)a+(dynamic)b;
}
We use only double type for T
class MyClass
{
double Add(double a, double b)
=> a + b;
}
For Struct we have no defined operation
+, so to maintain generic MyClass<T> we
need to cast to dynamic and we make
boxing ☹
We use only double type for T
# Memory snapshot
Total memory old
Total memory new
Total memory diff
Percent
140,550 MB
130,288 MB
7 %
-10,262 MB
# Still too much char[ ]?
/*
Collect single element of csv
string
*/
item=new List<char>();
/*.....*/
return item.ToArray();
# REUSE StringBuilder
char[] item
_stringBuilder.Clear();
/*.....*/
_stringBuilder.Write(item);
return item;
Cache StringBuilder in private field
No new Allocation
Can be used for different item
lengths
Can grow in 8,000 bytes if it’s
necessary to expand the internal buffer
# Memory snapshot
Total memory old
Total memory new
Total memory diff
Percent
59,565 MB
43,338 MB
27 %
-16,227 MB
# TOO MUCH <>c_DisplayClass26_0?
void AddValue(string key,string val)
/* Redundant lambda all data read
only */
dict.TryAdd(key,()=>new Data(val));
/*.....*/
# Memory snapshot
Total memory old
Total memory new
Total memory diff
Percent
34,243 MB
33,118 MB
3 %
-1,125 MB
The Second Challenge
WinForms .NET Applications
Read *.bin, *.txt data
files
“Process bits”, extract
and use full data, pack
into new format
It works correctly
Write results in text
and binary files
Use .NET
Framework 4.0
Run on Windows 10 x64
Measurements
dotMemory Snapshot
dotTrace TimeLine Sample & Snapshot Execution Time
Is It an bottleneck?
# Is Linq an bottleneck?
Potential Improvements
Used .ToArray() - slow
Concat use foreach and extra
memory to iterate input params
Each time we produce new byte array.
Redundant memory traffic.
var b = new byte[];
for (int i = 0; i < N; i++)
{
byte[] a = new byte[GetLen(i)];
/* fill a with values */
b = b.Concat(a).ToArray();
}
return b;
Buffer.BlockCopy
public static void BlockCopy
(Array src, int srcOffset, Array
dst, int dstOffset,
int count);
Copies a specified number of bytes from a
source array starting at a particular offset to a
destination array starting at a particular offset.
● src – Array The source buffer.
● srcOffset - Int32 The
zero-based byte offset into src.
● dst – Array The destination
buffer.
● dstOffset - Int32 The
zero-based byte offset into
dst.
● count - Int32 The number of
bytes to copy.
Comparison
var b = new byte[];
for (int i = 0; i < N; i++)
{
byte[] a = new byte[GetLen(i)];
/* fill a with values */
b = b.Concat(a).ToArray();
}
return b;
var b = new byte[maxN]; var bN=0;
for (int i = 0; i < N; i++)
{
var aN = GetLen(i);
byte[] a = new byte[aN];
/* fill a with values */
Buffer.BlockCopy(aN,0,b,bN,aN);
bN += aN;
}
return b;
#1 Performance Summary
Execution time
1st 374,011
120,333
68,83 %
-38 m 25 s 228 ms
Memory (MB)
2nd
Diff
%
43 m 21 s 642 ms
4 m 56 s 414 ms
-253,678
88,61 %
х 3,11
х 9,25
# Is FileStream.get_Length an bottleneck?
In both cases, the binary file read and
the basis on read data is the
calculated number of binary chains.
Potential Improvements
using(var br = new BinaryReader(…))
{
while (br.BaseStream.Position <= br.BaseStream.Length - 4)
{
counter++;
br.ReadUInt32();
br.ReadUInt32();
var n = br.ReadUInt32();
for (int i = 0; i < n; i++) br.ReadUInt32();
}
}
Redundant Length calls
Redundant subtraction
Redundant call
ReadUInt32
Solution
using(var br = new BinaryReader(…))
{
var length = br.BaseStream.Length - 4;
while (br.BaseStream.Position <= length)
{
counter++;
br.ReadUInt64();
var n = br.ReadUInt32();
for (int i = 0; i < n; i++) br.ReadUInt32();
}
}
Store Length in local
variable
Call ReadUInt64 instead
ReadUInt32
Comparison
using(var br = new BinaryReader(…))
{
while (br.BaseStream.Position <= br.BaseStream.Length - 4)
{
counter++;
br.ReadUInt32();
br.ReadUInt32();
var n = br.ReadUInt32();
for (int i = 0; i < n; i++) br.ReadUInt32();
}
}
using(var br = new BinaryReader(…))
{
var length = br.BaseStream.Length - 4;
while (br.BaseStream.Position <= length)
{
counter++;
br.ReadUInt64();
var n = br.ReadUInt32();
for (int i = 0; i < n; i++) br.ReadUInt32();
}
}
# Performance Summary
Execution time
Old 103,775
103,775
0.00 %
-31 s 786 ms
Memory (MB)
New
Diff
%
2 m 11 s 091 ms
1 m 39 s 305 ms
0
24.25 %
х 1.00
х 1.32
# ScaleGrad. - Can It Be Faster?
/*
Return index of number x by ordered
scale
*/
int ScaleGrad(int x)
Potential Improvements
static double[] Scale;
…
/* 600+ lines of code */
…
int ScaleGrad(int x)
{
for(int i=0; i<Scale.Length && Scale[i]<=x; i++)
return i - 1;
}
Avoid compare int and
double values
Scale is a sorted array, so
we can use binary search;
it’s more efficient and less
dependent on input data
Comparison
static double[] Scale;
/* 600+ lins of code */
int ScaleGrad(int x)
{
for(int i=0;(i<Scale.Length)&&(Scale[i]<= x);i++);
return i - 1;
}
static int[] Scale;
/* 600+ lins of code */
int ScaleGrad(int x)
var left = 1; var right = Scale.Length -1;
var mid =(left + right)>>1;//(left+right)/2
do {
mid = left + ((right - left)>>1);
if ( x < Scale[mid]) right = mid - 1;
else left = mid + 1;
} while (right >= left);
return mid;
#9 Performance Summary
Execution time
Old 9,754
9,754
0.00 %
-3 s 707 ms
Memory (MB)
New
Diff
%
32 s 551 ms
28 s 844 ms
0
11.39 %
х 1.00
х 1.13
Summary
PLEASE JOIN OUR WORKSHOP
TO SEE ALL OPTIMIZATION STEPS
Thank you!
Q&A
LINKS
Use dotTrace Command-Line Profiler Hashtable and dictionary collection types
.NET Performance Optimization &
Profiling with JetBrains dotTrace
Why GC run when using a struct as a
generic dictionary
Matt Ellis. Writing Allocation Free Code
in C#
Maarten Balliauw. Let’s refresh our
memory! Memory management in .NET
Sasha Goldshtein. Pro .NET Performance:
Optimize Your C# Applications
Ben Watson. Writing High-Performance
.NET Code, 2nd Edition
Maarten Balliauw
LINKS
Sasha Goldshtein
Yevhen Tatarynov GitHub
Writing Faster Managed Code: Know
What Things Cost
Ling.Concat
Linq.Concat Implementation
Buffer.BlockCopy
Generic List implementation
Konrad Kokosa. High-performance code
design patterns in C#
Ad

More Related Content

Similar to "Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov (20)

CPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesCPP-overviews notes variable data types notes
CPP-overviews notes variable data types notes
SukhpreetSingh519414
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
LogeekNightUkraine
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptx
WatchDog13
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
AnkurSingh656748
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
tdc-globalcode
 
Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)
Dina Goldshtein
 
Oops presentation
Oops presentationOops presentation
Oops presentation
sushamaGavarskar1
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
lodhran-hayat
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
Luis Enrique
 
Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1Object Oriented Programming (OOP) using C++ - Lecture 1
Object Oriented Programming (OOP) using C++ - Lecture 1
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its authorKaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Vivian S. Zhang
 
CUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : NotesCUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : Notes
Subhajit Sahu
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
Mukesh Tekwani
 
c++ introduction, array, pointers included.pptx
c++ introduction, array, pointers included.pptxc++ introduction, array, pointers included.pptx
c++ introduction, array, pointers included.pptx
fn723290
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit Pandey
 
Golang in TiDB (GopherChina 2017)
Golang in TiDB  (GopherChina 2017)Golang in TiDB  (GopherChina 2017)
Golang in TiDB (GopherChina 2017)
PingCAP
 
Implementation of Computational Algorithms using Parallel Programming
Implementation of Computational Algorithms using Parallel ProgrammingImplementation of Computational Algorithms using Parallel Programming
Implementation of Computational Algorithms using Parallel Programming
ijtsrd
 
01_intro-cpp.ppt
01_intro-cpp.ppt01_intro-cpp.ppt
01_intro-cpp.ppt
DrBashirMSaad
 
01_intro-cpp.ppt
01_intro-cpp.ppt01_intro-cpp.ppt
01_intro-cpp.ppt
SWETHAABIRAMIM
 
CPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesCPP-overviews notes variable data types notes
CPP-overviews notes variable data types notes
SukhpreetSingh519414
 
Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"Yevhen Tatarynov "From POC to High-Performance .NET applications"
Yevhen Tatarynov "From POC to High-Performance .NET applications"
LogeekNightUkraine
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptx
WatchDog13
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
tdc-globalcode
 
Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)
Dina Goldshtein
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 
Arrry structure Stacks in data structure
Arrry structure Stacks  in data structureArrry structure Stacks  in data structure
Arrry structure Stacks in data structure
lodhran-hayat
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
Luis Enrique
 
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its authorKaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author
Vivian S. Zhang
 
CUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : NotesCUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : Notes
Subhajit Sahu
 
c++ introduction, array, pointers included.pptx
c++ introduction, array, pointers included.pptxc++ introduction, array, pointers included.pptx
c++ introduction, array, pointers included.pptx
fn723290
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit Pandey
 
Golang in TiDB (GopherChina 2017)
Golang in TiDB  (GopherChina 2017)Golang in TiDB  (GopherChina 2017)
Golang in TiDB (GopherChina 2017)
PingCAP
 
Implementation of Computational Algorithms using Parallel Programming
Implementation of Computational Algorithms using Parallel ProgrammingImplementation of Computational Algorithms using Parallel Programming
Implementation of Computational Algorithms using Parallel Programming
ijtsrd
 

More from Fwdays (20)

Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...
Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...
Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...
Fwdays
 
"Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her...
"Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her..."Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her...
"Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her...
Fwdays
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
"Must-have AI-tools for cost-efficient marketing", Irina Smirnova
"Must-have AI-tools for cost-efficient marketing",  Irina Smirnova"Must-have AI-tools for cost-efficient marketing",  Irina Smirnova
"Must-have AI-tools for cost-efficient marketing", Irina Smirnova
Fwdays
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy
"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy
"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy
Fwdays
 
"Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies", V...
"Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies",  V..."Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies",  V...
"Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies", V...
Fwdays
 
"Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka...
"Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka..."Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka...
"Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka...
Fwdays
 
Performance Marketing Research для запуску нового WorldWide продукту
Performance Marketing Research для запуску нового WorldWide продуктуPerformance Marketing Research для запуску нового WorldWide продукту
Performance Marketing Research для запуску нового WorldWide продукту
Fwdays
 
"Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu...
"Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu..."Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu...
"Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu...
Fwdays
 
"AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea...
"AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea..."AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea...
"AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea...
Fwdays
 
"Constructive Interaction During Emotional Burnout: With Local and Internatio...
"Constructive Interaction During Emotional Burnout: With Local and Internatio..."Constructive Interaction During Emotional Burnout: With Local and Internatio...
"Constructive Interaction During Emotional Burnout: With Local and Internatio...
Fwdays
 
"Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil...
"Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil..."Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil...
"Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil...
Fwdays
 
"39 offers for my mentees in a year. How to create a professional environment...
"39 offers for my mentees in a year. How to create a professional environment..."39 offers for my mentees in a year. How to create a professional environment...
"39 offers for my mentees in a year. How to create a professional environment...
Fwdays
 
"From “doing tasks” to leadership: how to adapt management style to the conte...
"From “doing tasks” to leadership: how to adapt management style to the conte..."From “doing tasks” to leadership: how to adapt management style to the conte...
"From “doing tasks” to leadership: how to adapt management style to the conte...
Fwdays
 
[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...
[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...
[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...
Fwdays
 
[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...
[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...
[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...
Fwdays
 
[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...
[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...
[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...
Fwdays
 
"Dialogue about fakapas: how to pass an interview without unnecessary mistake...
"Dialogue about fakapas: how to pass an interview without unnecessary mistake..."Dialogue about fakapas: how to pass an interview without unnecessary mistake...
"Dialogue about fakapas: how to pass an interview without unnecessary mistake...
Fwdays
 
"Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest...
"Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest..."Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest...
"Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest...
Fwdays
 
Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...
Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...
Від KPI до OKR: як синхронізувати продажі, маркетинг і продукт, щоб бізнес ре...
Fwdays
 
"Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her...
"Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her..."Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her...
"Demand Generation: How a Founder’s Brand Turns Content into Leads", Alex Her...
Fwdays
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
"Must-have AI-tools for cost-efficient marketing", Irina Smirnova
"Must-have AI-tools for cost-efficient marketing",  Irina Smirnova"Must-have AI-tools for cost-efficient marketing",  Irina Smirnova
"Must-have AI-tools for cost-efficient marketing", Irina Smirnova
Fwdays
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy
"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy
"Building a Product IT Team in a Defense-Tech Company", Arthur Seletskiy
Fwdays
 
"Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies", V...
"Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies",  V..."Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies",  V...
"Scaling Smart: GTM Strategies that Fuel Growth for Service IT Companies", V...
Fwdays
 
"Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka...
"Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka..."Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka...
"Pushy Sales Don’t Work: How to Sell Without Driving People Crazy", Aliona Ka...
Fwdays
 
Performance Marketing Research для запуску нового WorldWide продукту
Performance Marketing Research для запуску нового WorldWide продуктуPerformance Marketing Research для запуску нового WorldWide продукту
Performance Marketing Research для запуску нового WorldWide продукту
Fwdays
 
"Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu...
"Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu..."Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu...
"Scaling Product Mindset: From Individual Ideas to Team Culture", Oksana Holu...
Fwdays
 
"AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea...
"AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea..."AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea...
"AI-Driven Automation for High-Performing Teams: Optimize Routine Tasks & Lea...
Fwdays
 
"Constructive Interaction During Emotional Burnout: With Local and Internatio...
"Constructive Interaction During Emotional Burnout: With Local and Internatio..."Constructive Interaction During Emotional Burnout: With Local and Internatio...
"Constructive Interaction During Emotional Burnout: With Local and Internatio...
Fwdays
 
"Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil...
"Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil..."Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil...
"Perfectionisin: What Does the Medicine for Perfectionism Look Like?", Manoil...
Fwdays
 
"39 offers for my mentees in a year. How to create a professional environment...
"39 offers for my mentees in a year. How to create a professional environment..."39 offers for my mentees in a year. How to create a professional environment...
"39 offers for my mentees in a year. How to create a professional environment...
Fwdays
 
"From “doing tasks” to leadership: how to adapt management style to the conte...
"From “doing tasks” to leadership: how to adapt management style to the conte..."From “doing tasks” to leadership: how to adapt management style to the conte...
"From “doing tasks” to leadership: how to adapt management style to the conte...
Fwdays
 
[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...
[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...
[QUICK TALK] "Why Some Teams Grow Better Under Pressure", Oleksandr Marchenko...
Fwdays
 
[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...
[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...
[QUICK TALK] "How to study to acquire a skill, not a certificate?", Uliana Du...
Fwdays
 
[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...
[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...
[QUICK TALK] "Coaching 101: How to Identify and Develop Your Leadership Quali...
Fwdays
 
"Dialogue about fakapas: how to pass an interview without unnecessary mistake...
"Dialogue about fakapas: how to pass an interview without unnecessary mistake..."Dialogue about fakapas: how to pass an interview without unnecessary mistake...
"Dialogue about fakapas: how to pass an interview without unnecessary mistake...
Fwdays
 
"Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest...
"Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest..."Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest...
"Conflicts within a Team: Not an Enemy, But an Opportunity for Growth", Orest...
Fwdays
 
Ad

Recently uploaded (20)

Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Financial Services Technology Summit 2025
Financial Services Technology Summit 2025Financial Services Technology Summit 2025
Financial Services Technology Summit 2025
Ray Bugg
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Does Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should KnowDoes Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should Know
Pornify CC
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Financial Services Technology Summit 2025
Financial Services Technology Summit 2025Financial Services Technology Summit 2025
Financial Services Technology Summit 2025
Ray Bugg
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Does Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should KnowDoes Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should Know
Pornify CC
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Ad

"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov

  • 2. Yevhen Tatarynov Software developer with 15 years of experience in commercial software and database development (.NET / MS SQL / Delphi) PhD in math, specializing in the theoretical foundations of computer science and cybernetics I was involved in projects performing complex mathematical calculations and processing large amounts of data. For now my role senior software developer in infrastructure team, Covent IT. Point of professional interest: application performance optimization and analysis writing C# code similar in performance to C++ advanced debugging
  • 3. Agenda The first challenge? Measurements To much … ? Summary QA The second challenge? Is It an bottleneck? Measurements
  • 5. Console .NET application Read *.csv data files Process data in multiple threads Write results in MS Excel file Use .NET Framework 4.6.2 Run on Windows It works correctly
  • 7. Measurement Tools DotNetBenchmark Visual Studio Performance Profiler Perfview R# dotTrace R# dotMemory Performance monitor
  • 12. # Too many code issues? Unused variables Unused properties Unused objects not allocated Unused data not loaded from files Unused fields don’t increase object size
  • 13. # Memory snapshot Total memory old Total memory new Total memory diff Percent 419,750 MB 359,971 MB 14 % -55,599 MB
  • 14. # Too many keys ConcurrentDictionary<MyKey,string> public struct MyKey { string field1; string field2; /*.....*/ }
  • 15. Boxing ConcurrentDictionary<TKey,TValue> classes have the same functionality as the Hashtable class. A ConcurrentDictionary <TKey,TValue> of a specific type (other than Object) provides better performance than a Hashtable for value types. This is because the elements of Hashtable are of type Object; therefore, boxing and unboxing typically occur when you store or retrieve a value type.
  • 16. StackOverflow Since you only override Equals and don’t implement IEquatable<T>, the dictionary is forced to box one of the two instances whenever it compares two of them for equality because it's passing an instance into an Equals-method-accepting object. If you implement IEquatable<T>, then the dictionary can (and will) use the version of Equals that accepts the parameter as a T, which won't require boxing.
  • 17. IEquatable interface public struct MyKey : IEquatable<MyKey> { string field1; string field2; string field3; /*.....*/ public bool Equals(MyKey other); }
  • 18. # Memory snapshot Total memory old Total memory new Total memory diff Percent 359,971 MB 137,294 MB 65 % -251,654 MB
  • 19. # Too much System.Double in heap? class MyClass<T> where T : struct { T Add(T a, T b) => (dynamic)a+(dynamic)b; }
  • 20. We use only double type for T class MyClass { double Add(double a, double b) => a + b; } For Struct we have no defined operation +, so to maintain generic MyClass<T> we need to cast to dynamic and we make boxing ☹ We use only double type for T
  • 21. # Memory snapshot Total memory old Total memory new Total memory diff Percent 140,550 MB 130,288 MB 7 % -10,262 MB
  • 22. # Still too much char[ ]? /* Collect single element of csv string */ item=new List<char>(); /*.....*/ return item.ToArray();
  • 23. # REUSE StringBuilder char[] item _stringBuilder.Clear(); /*.....*/ _stringBuilder.Write(item); return item; Cache StringBuilder in private field No new Allocation Can be used for different item lengths Can grow in 8,000 bytes if it’s necessary to expand the internal buffer
  • 24. # Memory snapshot Total memory old Total memory new Total memory diff Percent 59,565 MB 43,338 MB 27 % -16,227 MB
  • 25. # TOO MUCH <>c_DisplayClass26_0? void AddValue(string key,string val) /* Redundant lambda all data read only */ dict.TryAdd(key,()=>new Data(val)); /*.....*/
  • 26. # Memory snapshot Total memory old Total memory new Total memory diff Percent 34,243 MB 33,118 MB 3 % -1,125 MB
  • 28. WinForms .NET Applications Read *.bin, *.txt data files “Process bits”, extract and use full data, pack into new format It works correctly Write results in text and binary files Use .NET Framework 4.0 Run on Windows 10 x64
  • 31. dotTrace TimeLine Sample & Snapshot Execution Time
  • 32. Is It an bottleneck?
  • 33. # Is Linq an bottleneck?
  • 34. Potential Improvements Used .ToArray() - slow Concat use foreach and extra memory to iterate input params Each time we produce new byte array. Redundant memory traffic. var b = new byte[]; for (int i = 0; i < N; i++) { byte[] a = new byte[GetLen(i)]; /* fill a with values */ b = b.Concat(a).ToArray(); } return b;
  • 35. Buffer.BlockCopy public static void BlockCopy (Array src, int srcOffset, Array dst, int dstOffset, int count); Copies a specified number of bytes from a source array starting at a particular offset to a destination array starting at a particular offset. ● src – Array The source buffer. ● srcOffset - Int32 The zero-based byte offset into src. ● dst – Array The destination buffer. ● dstOffset - Int32 The zero-based byte offset into dst. ● count - Int32 The number of bytes to copy.
  • 36. Comparison var b = new byte[]; for (int i = 0; i < N; i++) { byte[] a = new byte[GetLen(i)]; /* fill a with values */ b = b.Concat(a).ToArray(); } return b; var b = new byte[maxN]; var bN=0; for (int i = 0; i < N; i++) { var aN = GetLen(i); byte[] a = new byte[aN]; /* fill a with values */ Buffer.BlockCopy(aN,0,b,bN,aN); bN += aN; } return b;
  • 37. #1 Performance Summary Execution time 1st 374,011 120,333 68,83 % -38 m 25 s 228 ms Memory (MB) 2nd Diff % 43 m 21 s 642 ms 4 m 56 s 414 ms -253,678 88,61 % х 3,11 х 9,25
  • 38. # Is FileStream.get_Length an bottleneck? In both cases, the binary file read and the basis on read data is the calculated number of binary chains.
  • 39. Potential Improvements using(var br = new BinaryReader(…)) { while (br.BaseStream.Position <= br.BaseStream.Length - 4) { counter++; br.ReadUInt32(); br.ReadUInt32(); var n = br.ReadUInt32(); for (int i = 0; i < n; i++) br.ReadUInt32(); } } Redundant Length calls Redundant subtraction Redundant call ReadUInt32
  • 40. Solution using(var br = new BinaryReader(…)) { var length = br.BaseStream.Length - 4; while (br.BaseStream.Position <= length) { counter++; br.ReadUInt64(); var n = br.ReadUInt32(); for (int i = 0; i < n; i++) br.ReadUInt32(); } } Store Length in local variable Call ReadUInt64 instead ReadUInt32
  • 41. Comparison using(var br = new BinaryReader(…)) { while (br.BaseStream.Position <= br.BaseStream.Length - 4) { counter++; br.ReadUInt32(); br.ReadUInt32(); var n = br.ReadUInt32(); for (int i = 0; i < n; i++) br.ReadUInt32(); } } using(var br = new BinaryReader(…)) { var length = br.BaseStream.Length - 4; while (br.BaseStream.Position <= length) { counter++; br.ReadUInt64(); var n = br.ReadUInt32(); for (int i = 0; i < n; i++) br.ReadUInt32(); } }
  • 42. # Performance Summary Execution time Old 103,775 103,775 0.00 % -31 s 786 ms Memory (MB) New Diff % 2 m 11 s 091 ms 1 m 39 s 305 ms 0 24.25 % х 1.00 х 1.32
  • 43. # ScaleGrad. - Can It Be Faster? /* Return index of number x by ordered scale */ int ScaleGrad(int x)
  • 44. Potential Improvements static double[] Scale; … /* 600+ lines of code */ … int ScaleGrad(int x) { for(int i=0; i<Scale.Length && Scale[i]<=x; i++) return i - 1; } Avoid compare int and double values Scale is a sorted array, so we can use binary search; it’s more efficient and less dependent on input data
  • 45. Comparison static double[] Scale; /* 600+ lins of code */ int ScaleGrad(int x) { for(int i=0;(i<Scale.Length)&&(Scale[i]<= x);i++); return i - 1; } static int[] Scale; /* 600+ lins of code */ int ScaleGrad(int x) var left = 1; var right = Scale.Length -1; var mid =(left + right)>>1;//(left+right)/2 do { mid = left + ((right - left)>>1); if ( x < Scale[mid]) right = mid - 1; else left = mid + 1; } while (right >= left); return mid;
  • 46. #9 Performance Summary Execution time Old 9,754 9,754 0.00 % -3 s 707 ms Memory (MB) New Diff % 32 s 551 ms 28 s 844 ms 0 11.39 % х 1.00 х 1.13
  • 48. PLEASE JOIN OUR WORKSHOP TO SEE ALL OPTIMIZATION STEPS
  • 50. Q&A
  • 51. LINKS Use dotTrace Command-Line Profiler Hashtable and dictionary collection types .NET Performance Optimization & Profiling with JetBrains dotTrace Why GC run when using a struct as a generic dictionary Matt Ellis. Writing Allocation Free Code in C# Maarten Balliauw. Let’s refresh our memory! Memory management in .NET Sasha Goldshtein. Pro .NET Performance: Optimize Your C# Applications Ben Watson. Writing High-Performance .NET Code, 2nd Edition
  • 52. Maarten Balliauw LINKS Sasha Goldshtein Yevhen Tatarynov GitHub Writing Faster Managed Code: Know What Things Cost Ling.Concat Linq.Concat Implementation Buffer.BlockCopy Generic List implementation Konrad Kokosa. High-performance code design patterns in C#
  翻译: