developing high performance applications with the.net compact framework (400) patrick derks...
Post on 21-Dec-2015
226 views
TRANSCRIPT
Developing High Developing High Performance Applications Performance Applications With the .NET Compact With the .NET Compact Framework (400)Framework (400)
Patrick Derks ([email protected])Patrick Derks ([email protected])Mobile Devices Mobile Devices Microsoft CorporationMicrosoft Corporation
AgendaAgenda
OverviewOverview
JIT CompilerJIT Compiler
Garbage Collector (GC)Garbage Collector (GC)Sources of GarbageSources of Garbage
Finalize & DisposeFinalize & Dispose
ReflectionReflection
XMLXML
DataDataLocal & RemoteLocal & Remote
MManagementanagementTToolsools
CCommunicationsommunications& & MMessagingessaging
Device Update Agent
Software Update Services
Live Communications Server
Exchange Server
Internet Security and Acceleration Server
Speech Server
Image Update
LLocation ocation SServiceservices
MMultimediaultimedia
MapPoint
DirectX
Windows Media
Visual Studio 2005DDevelopment evelopment TToolsools
MFC 8.0, ATL 8.0
Win32NNativeative
MManagedanaged
SServer erver SSideide
LLightweightightweight
RRelationalelationalSQL Server 2005 Express EditionEDB
DDa
taata
PPro
gra
mm
ing
ro
gra
mm
ing
MM
od
el
od
el
DDevice evice BBuilding uilding TToolsools
HHardware/ardware/DDriversrivers
Windows XP DDK
Windows Embedded Studio
Platform Builder
OEM/IHV SuppliedBSP
(ARM, SH4, MIPS)OEM Hardware and Standard Drivers
Standard PC Hardware and Drivers
SQL Server 2005SQL Server 2005 Mobile Edition
ASP.NET Mobile Controls ASP.NET
.NET Compact Framework .NET Framework
Microsoft Operations Manager
Systems Management Server
Measuring PerformanceMeasuring PerformanceOverviewOverview
Micro-benchmarks versus ScenariosMicro-benchmarks versus Scenarios
Benchmarking tipsBenchmarking tipsUse Environment.TickCount to measureUse Environment.TickCount to measure
Measure times greater than 1 secondMeasure times greater than 1 second
Start from known stateStart from known state
Ensure nothing else is runningEnsure nothing else is running
Measure multiple times, take averageMeasure multiple times, take average
Run each test in own AppDomain / ProcessRun each test in own AppDomain / Process
Log results at the endLog results at the end
Understand JIT-time versus runtime costUnderstand JIT-time versus runtime cost
.NET Compact Framework.NET Compact Framework
.NET Compact Framework Performance v1->v2.NET Compact Framework Performance v1->v2
(Pocket PC 2003, XScale 400MHz)(Pocket PC 2003, XScale 400MHz) 1.01.0 1.0 SP31.0 SP3V2 V2
Beta1Beta1V2 B2+V2 B2+
Method Calls (Calls/sec) 3.7M 7.1M 8.1M
Virtual Calls (Calls/sec) 2.4M 2.7M 5.6M
Simple P/Invoke (Calls/sec) 733K 1.7M
Primes (to 1500) (iterations/sec) 562 832 853
GC Small (8 bytes) (Bytes/sec) 1M 7M 7.5M
GC Array (100 int’s) (Bytes/sec) 25M 43M 112M
XML Text Reader 200KB (seconds) 1.7 1.2 0.72 0.69
DataSet (static data)4 tables, 1000 records (seconds) 13.1 6.6 7.3 3.3
DataSet (ReadXml)3 tables, 100 records (seconds) 12.3 6.5 5.2 4.4
BiggerBiggeris betteris better
SmallerSmalleris betteris better
Measuring PerformanceMeasuring PerformancePerformance countersPerformance counters
<My App>.stat (formerly mscoree.stat)<My App>.stat (formerly mscoree.stat)http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfperf.asp
RegistryRegistryHKLM\SOFTWARE\Microsoft\.NETCompactFramework\PerfMonitorHKLM\SOFTWARE\Microsoft\.NETCompactFramework\PerfMonitorCounters (DWORD) = 1Counters (DWORD) = 1
What does .stat tell you?What does .stat tell you?Working set and performance statisticsWorking set and performance statistics
More counters added in v2More counters added in v2Generics usageGenerics usage
COM interop usageCOM interop usage
Number of boxed valuetypesNumber of boxed valuetypes
Threading and timersThreading and timers
GUI objectsGUI objects
Network activity (socket bytes send/received)Network activity (socket bytes send/received)
.stat.statcounter total last datum n mean min maxTotal Program Run Time (ms) 55937 - - - - -App Domains Created 18 - - - - -App Domains Unloaded 18 - - - - -Assemblies Loaded 323 - - - - -Classes Loaded 18852 - - - - -Methods Loaded 37353 - - - - -Closed Types Loaded 730 - - - - -Closed Types Loaded per Definition 730 8 385 1 1 8Open Types Loaded 78 - - - - -Closed Methods Loaded 46 - - - - -Closed Methods Loaded per Definition 46 1 40 1 1 2Open Methods Loaded 0 - - - - -Threads in Thread Pool - 0 6 1 0 3Pending Timers - 0 93 0 0 1Scheduled Timers 46 - - - - -Timers Delayed by Thread Pool Limit 0 - - - - -Work Items Queued 46 - - - - -Uncontested Monitor.Enter Calls 57240 - - - - -Contested Monitor.Enter Calls 0 - - - - -Peak Bytes Allocated (native + managed) 4024363 - - - - -Managed Objects Allocated 1015100 - - - - -Managed Bytes Allocated 37291444 28 1015100 36 8 55588Managed String Objects Allocated 112108 - - - - -Bytes of String Objects Allocated 4596658 - - - - -Garbage Collections (GC) 33 - - - - -Bytes Collected By GC 25573036 41592 33 774940 41592 1096328Managed Bytes In Use After GC - 23528 33 259414 23176 924612Total Bytes In Use After GC - 3091342 33 2954574 1833928 3988607GC Compactions 17 - - - - -Code Pitchings 6 - - - - -Calls to GC.Collect 0 - - - - -GC Latency Time (ms) 279 16 33 8 0 31Pinned Objects 156 - - - - -Objects Moved by Compactor 73760 - - - - -Objects Not Moved by Compactor 11811 - - - - -Objects Finalized 6383 - - - - -Boxed Value Types 350829 - - - - -Process Heap - 1626 430814 511970 952 962130Short Term Heap - 0 178228 718 0 21532JIT Heap - 0 88135 357796 0 651663App Domain Heap - 0 741720 647240 0 833370GC Heap - 0 376 855105 0 2097152Native Bytes Jitted 7202214 152 26910 267 80 5448Methods Jitted 26910 - - - - -Bytes Pitched 1673873 0 7047 237 0 5448
Peak Bytes Allocated (native + managed)
JIT Heap App Domain Heap GC Heap
GC Latency Time (ms)
Garbage Collections (GC)
Managed String Objects Allocated
Boxed Value Types
FXFX
.NET Compact Framework.NET Compact Framework
CLRCLR
Windows CEWindows CE
GlobalizationGlobalization GUIGUINetNetI/OI/OCryptoCrypto
System.System.GlobalizationGlobalization
System.System.CryptographyCryptography
System.System.IO.PortsIO.Ports
Microsoft.Microsoft.Win32.RegistryWin32.Registry
System.IO.System.IO.FileFile
System.System.DataData
System.XmlSystem.Xml
SystemSystem
mscorlibmscorlib
Microsoft.Microsoft.VisualBasicVisualBasic
JIT CompilerJIT Compiler& GC& GC
DebuggerDebugger
ClassClassLoaderLoader
AssemblyAssemblyCacheCache
NativeNativeInteropInterop
App DomainApp DomainLoaderLoader
ProcessProcessLoaderLoader
Memory and Memory and ThreadingThreading
File MappingFile MappingCert/SecurityCert/SecurityVerificationVerification
System.System.WebServicesWebServices
System.Net.System.Net.Http*Http*
System.Net.System.Net.SocketsSockets
DirectX.DirectX.DirectD3DMDirectD3DM
Windows.Windows.FormsForms
System.System.DrawingDrawing
SSLSSL
SocketsSockets
NTLMNTLM
GDI/GWESGDI/GWES
CommonCommonControlsControls
RegistryRegistry
File I/OFile I/O
EncodingsEncodings
SortingSorting Crypto APICrypto API
CalendarCalendarDataData
CultureCultureDataData
RedistRedist
HostHost
Visual StudioVisual Studio
Debug EngineDebug Engine
ICorDbgICorDbg
Managed LoaderManaged Loader
MSI SetupMSI Setup(ActiveSync)(ActiveSync)
Per Device CABPer Device CABInstall (SMS, etc)Install (SMS, etc)
System.System.ReflectionReflection
CasingCasing D3DMD3DM
.NET Compact Framework.NET Compact FrameworkHow we are different?How we are different?
Portable JIT CompilerPortable JIT CompilerFast code generation, less optimizedFast code generation, less optimized
May pitch JIT-compiled code under May pitch JIT-compiled code under memory pressurememory pressure
No NGen, install time or persisted codeNo NGen, install time or persisted code
Interpreted virtual calls (no v-tables)Interpreted virtual calls (no v-tables)
Simple mark and sweep GC, Simple mark and sweep GC, non generationalnon generational
Common Language RuntimeCommon Language RuntimeExecution EngineExecution Engine
Call pathCall pathManaged calls are more expensive than nativeManaged calls are more expensive than native
Instance call: ~2-3X the cost of a native function callInstance call: ~2-3X the cost of a native function call
Virtual call: ~1.4X the cost of a managed instance callVirtual call: ~1.4X the cost of a managed instance call
Platform invoke: ~5X the cost of managed instance call Platform invoke: ~5X the cost of managed instance call (*Marshal int parameter)(*Marshal int parameter)
Properties are callsProperties are calls
JIT compilersJIT compilersAll platforms has the same optimizing JIT compiler All platforms has the same optimizing JIT compiler architecture in v2architecture in v2
OptimizationsOptimizationsMethod inlining for simple methodsMethod inlining for simple methods
Variable enregistration Variable enregistration
String interningString interning
Common Language RuntimeCommon Language Runtime Call path (sample) Call path (sample)public class Shape public class Shape
{{
protected int m_volume; protected int m_volume;
public public virtualvirtual int Volume int Volume
{ {
get {return m_volume;}get {return m_volume;}
}}
}}
public class Cube:Shape public class Cube:Shape
{{
public MyType(int vol) public MyType(int vol)
{ {
m_volume = vol;m_volume = vol;
}}
}}
public class Shape public class Shape
{{
protected int m_volume; protected int m_volume;
public int Volume public int Volume
{ {
get {return m_volume;}get {return m_volume;}
}}
}}
public class Cube:Shape public class Cube:Shape
{{
public MyType(int vol) public MyType(int vol)
{ {
m_volume = vol;m_volume = vol;
}}
}}
Common Language RuntimeCommon Language Runtime Call path (sample) Call path (sample) public class MyCollectionpublic class MyCollection
{{private const int m_capacity = 10000;private const int m_capacity = 10000;private Shape[] storage = new Shape[m_capacity];private Shape[] storage = new Shape[m_capacity];……public void Sort()public void Sort(){{
Shape tmp;Shape tmp; for (int i=0; i<m_capacity-1; i++) {for (int i=0; i<m_capacity-1; i++) {
for (int j=0; j<m_capacity-1-i; j++)for (int j=0; j<m_capacity-1-i; j++) if (if (storage[j+1].Volumestorage[j+1].Volume < < storage[j].Volumestorage[j].Volume){ ){
tmp = storage[j]; tmp = storage[j]; storage[j] = storage[j+1];storage[j] = storage[j+1];storage[j+1] = tmp;storage[j+1] = tmp;
}} }}}}
}}
callvirt instance int32 Shape::get_Volume()
Common Language RuntimeCommon Language Runtime Call path (sample) Call path (sample)
public class Shape public class Shape
{{
protected int m_volume; protected int m_volume;
public public virtualvirtual int Volume int Volume
{ {
get {return m_volume;}get {return m_volume;}
}}
}}
public class Cube:Shape public class Cube:Shape
{{
public MyType(int vol) public MyType(int vol)
{ {
m_volume = vol;m_volume = vol;
}}
}}
public class Shape public class Shape
{{
protected int m_volume; protected int m_volume;
public int Volume public int Volume
{ {
get {return m_volume;}get {return m_volume;}
}}
}}
public class Cube:Shape public class Cube:Shape
{{
public MyType(int vol) public MyType(int vol)
{ {
m_volume = vol;m_volume = vol;
}}
}}
•No virtual call overheadNo virtual call overhead
•Inlined (no call overhead at all)Inlined (no call overhead at all)
~ Equal to accessing field~ Equal to accessing field
57 sec57 sec 39 sec39 sec
Common Language RuntimeCommon Language RuntimeGarbage CollectorGarbage Collector
What triggers a GC?What triggers a GC?Memory allocation failureMemory allocation failure1M of GC objects allocated (v2)1M of GC objects allocated (v2)Application going to backgroundApplication going to backgroundGC.Collect() (Avoid “helping” the GC!)GC.Collect() (Avoid “helping” the GC!)
What happens at GC time?What happens at GC time?Freezes all threads at safe pointFreezes all threads at safe pointFinds all live objects and marks themFinds all live objects and marks them
An object is live if it is reachable from root locationAn object is live if it is reachable from root locationUnmarked objects are freed and added to finalizer queueUnmarked objects are freed and added to finalizer queue
Finalizers are run on a separate threadFinalizers are run on a separate threadGC pools are compacted if required (less than 750K of GC pools are compacted if required (less than 750K of free space)free space)Return free memory to the operating systemReturn free memory to the operating system
In general, if you don’t allocate objects, In general, if you don’t allocate objects, GC won’t occurGC won’t occur
Beware of side-effects of calls that may allocate objectsBeware of side-effects of calls that may allocate objects
Common Language RuntimeCommon Language RuntimeGarbage CollectorGarbage Collector
0
10
20
30
40
50
60
70
80
90
0 100000 300000 500000
Number of Live Objects
GC
late
nc
y (
ms
)
GC Latency per collection
Common Language RuntimeCommon Language RuntimeGarbage CollectorGarbage Collector
0
20000
40000
60000
80000
100000
120000
140000
160000
400 4000 20000 40000 80000
Object size (bytes)
All
oc
ati
on
ra
te i
ter/
se
c
Allocation rate
Common Language RuntimeCommon Language RuntimeGarbage CollectorGarbage Collector
0
10
20
30
40
50
60
70
80
90
8 400 4000 20000 40000 80000
Object size (bytes)
Allo
ca
tio
n t
hro
ug
hp
ut
Mb
/se
c
Allocation throughput
Common Language RuntimeCommon Language RuntimeWhere garbage comes from?Where garbage comes from?
Unnecessary string copiesUnnecessary string copiesStrings are immutable Strings are immutable
String manipulations (Concat(), etc.) String manipulations (Concat(), etc.) cause copies cause copies Use StringBuilder Use StringBuilder http://weblogs.asp.net/ricom/archive/2003/12/02/40778.aspx
String result = "";String result = "";
for (int i=0; i<10000; i++) {for (int i=0; i<10000; i++) {
result += result +=
".NET Compact Framework";".NET Compact Framework";
result += " Rocks!";result += " Rocks!";
} }
StringBuilder result = StringBuilder result =
new StringBuilder();new StringBuilder();
for (int i=0; i<10000; i++){for (int i=0; i<10000; i++){
result.Append(".NET Compact result.Append(".NET Compact Framework");Framework");
result.Append(" Rocks!");result.Append(" Rocks!");
}}
.stat.statcounter total last datum n mean min maxTotal Program Run Time (ms) 11843 - - - - -App Domains Created 1 - - - - -App Domains Unloaded 1 - - - - -Assemblies Loaded 2 - - - - -Classes Loaded 175 - - - - -Methods Loaded 198 - - - - -Closed Types Loaded 0 - - - - -Closed Types Loaded per Definition 0 0 0 0 0 0Open Types Loaded 0 - - - - -Closed Methods Loaded 0 - - - - -Closed Methods Loaded per Definition 0 0 0 0 0 0Open Methods Loaded 0 - - - - -Threads in Thread Pool - 0 2 0 0 1Pending Timers - 0 2 0 0 1Scheduled Timers 1 - - - - -Timers Delayed by Thread Pool Limit 0 - - - - -Work Items Queued 1 - - - - -Uncontested Monitor.Enter Calls 2 - - - - -Contested Monitor.Enter Calls 0 - - - - -Peak Bytes Allocated (native + managed) 3326004 - - - - -Managed Objects Allocated 60266 - - - - -Managed Bytes Allocated 5801679432 28 60266 96267 8 580020Managed String Objects Allocated 20041 - - - - -Bytes of String Objects Allocated 5800480578 - - - - -Garbage Collections (GC) 4912 - - - - -Bytes Collected By GC 5918699036 1160076 4912 1204946 597824 1572512Managed Bytes In Use After GC - 580752 4912 381831 8364 580752Total Bytes In Use After GC - 1810560 4912 1611885 1097856 1810560GC Compactions 0 - - - - -Code Pitchings 0 - - - - -Calls to GC.Collect 0 - - - - -GC Latency Time (ms) 686 0 4912 0 0 16Pinned Objects 0 - - - - -Objects Moved by Compactor 0 - - - - -Objects Not Moved by Compactor 0 - - - - -Objects Finalized 1 - - - - -Boxed Value Types 3 - - - - -Process Heap - 278 235 2352 68 8733Short Term Heap - 0 278 986 0 10424JIT Heap - 0 360 12103 0 24444App Domain Heap - 0 1341 46799 0 64562GC Heap - 0 35524 2095727 0 3276800Native Bytes Jitted 22427 140 98 228 68 1367Methods Jitted 98 - - - - -Bytes Pitched 0 0 0 0 0 0Methods Pitched 0 - - - - -Method Pitch Latency Time (ms) 0 0 0 0 0 0Exceptions Thrown 0 - - - - -Platform Invoke Calls 0 - - - - -
Managed String Objects Allocated 20040Garbage Collections (GC) 4912Bytes of String Objects Allocate 5,800,480,574Bytes Collected By GC 5,918,699,036GC latency 107128 ms
String result = "";for (int i=0; i<10000; i++) { result += ".NET Compact Framework"; result += " Rocks!";}
Run time 173 secRun time 173 sec
counter total last datum n mean min maxTotal Program Run Time (ms) 11843 - - - - -App Domains Created 1 - - - - -App Domains Unloaded 1 - - - - -Assemblies Loaded 2 - - - - -Classes Loaded 175 - - - - -Methods Loaded 198 - - - - -Closed Types Loaded 0 - - - - -Closed Types Loaded per Definition 0 0 0 0 0 0Open Types Loaded 0 - - - - -Closed Methods Loaded 0 - - - - -Closed Methods Loaded per Definition 0 0 0 0 0 0Open Methods Loaded 0 - - - - -Threads in Thread Pool - 0 2 0 0 1Pending Timers - 0 2 0 0 1Scheduled Timers 1 - - - - -Timers Delayed by Thread Pool Limit 0 - - - - -Work Items Queued 1 - - - - -Uncontested Monitor.Enter Calls 2 - - - - -Contested Monitor.Enter Calls 0 - - - - -Peak Bytes Allocated (native + managed) 3326004 - - - - -Managed Objects Allocated 60266 - - - - -Managed Bytes Allocated 5801679432 28 60266 96267 8 580020Managed String Objects Allocated 20041 - - - - -Bytes of String Objects Allocated 5800480578 - - - - -Garbage Collections (GC) 4912 - - - - -Bytes Collected By GC 5918699036 1160076 4912 1204946 597824 1572512Managed Bytes In Use After GC - 580752 4912 381831 8364 580752Total Bytes In Use After GC - 1810560 4912 1611885 1097856 1810560GC Compactions 0 - - - - -Code Pitchings 0 - - - - -Calls to GC.Collect 0 - - - - -GC Latency Time (ms) 686 0 4912 0 0 16Pinned Objects 0 - - - - -Objects Moved by Compactor 0 - - - - -Objects Not Moved by Compactor 0 - - - - -Objects Finalized 1 - - - - -Boxed Value Types 3 - - - - -Process Heap - 278 235 2352 68 8733Short Term Heap - 0 278 986 0 10424JIT Heap - 0 360 12103 0 24444App Domain Heap - 0 1341 46799 0 64562GC Heap - 0 35524 2095727 0 3276800Native Bytes Jitted 22427 140 98 228 68 1367Methods Jitted 98 - - - - -Bytes Pitched 0 0 0 0 0 0Methods Pitched 0 - - - - -Method Pitch Latency Time (ms) 0 0 0 0 0 0Exceptions Thrown 0 - - - - -Platform Invoke Calls 0 - - - - -
.stat.stat
Managed String Objects Allocated 56Bytes of String Objects Allocated 2097718Garbage Collections (GC) 2Bytes Collected By GC 1081620GC Latency 21 ms
StringBuilder result = new StringBuilder();for (int i=0; i<10000; i++){
result.Append(".NET Compact Framework");
result.Append(" Rocks!");}
Run time 0.1 secRun time 0.1 sec
Common Language RuntimeCommon Language RuntimeWhere garbage comes from?Where garbage comes from?
Unnecessary boxingUnnecessary boxingValue types allocated on the stack Value types allocated on the stack (fast to allocate)(fast to allocate)Boxing causes a heap allocation and a copyBoxing causes a heap allocation and a copyUse strongly typed arrays and collectionsUse strongly typed arrays and collections(framework collections are (framework collections are NOTNOT strongly typed) strongly typed)class Hashtable {class Hashtable {
struct bucket {struct bucket {Object keyObject key;;Object valObject val; ;
} } bucket[] buckets;bucket[] buckets;
public public ObjectObject this[ this[Object keyObject key] { get; set; }] { get; set; }}}
Common Language RuntimeCommon Language RuntimeSample Code: Value Types and boxing Sample Code: Value Types and boxing
public struct AccountId {public struct AccountId { public int m_number;public int m_number; public override int GetHashCode()public override int GetHashCode()
{return m_number; }{return m_number; }}}
public interface IAccountData { int Balance{get; set;}}
public struct AccountData : IAccountData { private int m_balance; public int Balance {
get {return m_balance;} set {m_balance=value;}
}}
public class Accounts { public const int num = 10000; IAccountData[] accounts = new IAccountData[num]; public IAccountData this[Object id] { get {return _accounts[id.GetHashCode()];} set {_accounts[id.GetHashCode()] = value;} }}
public struct AccountId {public struct AccountId { public int m_number;public int m_number; public override int GetHashCode() public override int GetHashCode()
{return m_number; }{return m_number; }}}
public struct AccountData {
private int m_balance;
public int Balance {
get {return m_balance;}
set {m_balance=value;}
}
}
public class Accounts {
public const int num = 10000;
AccountData[] accounts = new AccountData[num];
public AccountData this[AccountId id] {
get {return accounts[id.GetHashCode()];}
set {accounts[id.GetHashCode()] = value;}
}
}
Common Language RuntimeCommon Language RuntimeSample Code: Value Types and boxing Sample Code: Value Types and boxing
public struct AccountId { public int m_number; public override int GetHashCode()
{ return m_number; }}
public interface IAccountData { public interface IAccountData { int Balance{get; set;}int Balance{get; set;}}}
public struct AccountData : public struct AccountData : IAccountData {IAccountData {
private int m_balance;private int m_balance; public int Balance {public int Balance {
get {return m_balance;} get {return m_balance;} set {m_balance=value;}set {m_balance=value;}
}}}}
public class Accounts { public const int num = 10000; IAccountData[] accounts = new IAccountData[num]; public IAccountData this[Object id] { get {return _accounts[id.GetHashCode()];} set {_accounts[id.GetHashCode()] = value;} }}
public struct AccountId{
public int m_number;
public override int GetHashCode()
{return m_number;}
}
public struct AccountData {public struct AccountData {
private int m_balance;private int m_balance;
public int Balance {public int Balance {
get {return m_balance;}get {return m_balance;}
set {m_balance=value;} set {m_balance=value;}
}}
}}
public class Accounts {
public const int num = 10000;
AccountData[] accounts = new AccountData[num];
public AccountData this[AccountId id] {
get {return accounts[id.GetHashCode()];}
set {accounts[id.GetHashCode()] = value;}
}
}
Common Language RuntimeCommon Language RuntimeSample Code: Value Types and boxing Sample Code: Value Types and boxing
public struct AccountId{public struct AccountId{
public int m_number;public int m_number;
public override int GetHashCode() public override int GetHashCode()
{return m_number;}{return m_number;}
}}
public struct AccountData {public struct AccountData {
private int m_balance;private int m_balance;
public int Balance {public int Balance {
get {return m_balance;}get {return m_balance;}
set {m_balance=value;} set {m_balance=value;}
}}
}}
public class Accounts {public class Accounts {
public const int num = 10000;public const int num = 10000;
AccountData[] accounts = new AccountData[] accounts = new AccountData[num];AccountData[num];
public AccountData this[AccountId id] {public AccountData this[AccountId id] {
get {return accounts[id.GetHashCode()];}get {return accounts[id.GetHashCode()];}
set {accounts[id.GetHashCode()] = value;}set {accounts[id.GetHashCode()] = value;}
}}
}}
public struct AccountId { public int m_number; public override int GetHashCode()
{ return m_number; }}
public interface IAccountData { int Balance{get; set;}}
public struct AccountData : IAccountData { private int m_balance; public int Balance {
get {return m_balance;} set {m_balance=value;}
}}
public class Accounts {public class Accounts { public const int num = 10000;public const int num = 10000; IAccountData[] accounts = new IAccountData[] accounts = new
IAccountData[num];IAccountData[num]; public IAccountData public IAccountData
this[Object id] {this[Object id] { get {return get {return
accounts[id.GetHashCode()];}accounts[id.GetHashCode()];} set {accounts[id.GetHashCode()] set {accounts[id.GetHashCode()]
= value;}= value;} }}}}
public struct AccountId{
public int m_number;
public override int GetHashCode()
{return m_number;}
}
public struct AccountData {
private int m_balance;
public int Balance {
get {return m_balance;}
set {m_balance=value;}
}
}
public class Accounts {public class Accounts {
public const int num = 10000;public const int num = 10000;
AccountData[] accounts = new AccountData[] accounts = new AccountData[num];AccountData[num];
public AccountData this[AccountId public AccountData this[AccountId id] {id] {
get {return get {return accounts[id.GetHashCode()];}accounts[id.GetHashCode()];}
set {accounts[id.GetHashCode()] set {accounts[id.GetHashCode()] = value;}= value;}
}}
}}
Common Language RuntimeCommon Language RuntimeSample Code: Value Types and boxing Sample Code: Value Types and boxing
Accounts ac = new Accounts(); int i;Accounts ac = new Accounts(); int i;for (i = 0; i < Accounts.num_accounts; i++) {for (i = 0; i < Accounts.num_accounts; i++) {
AccountData rec = new AccountData();AccountData rec = new AccountData();rec.Balance = 100;rec.Balance = 100;AccountId id; id.m_number = i;AccountId id; id.m_number = i;ac[id] = rec;ac[id] = rec;
}}long iterations = 0;long iterations = 0;long start = Environment.TickCount;long start = Environment.TickCount;do {do {
for (i = 0; i < Accounts.num_accounts; i++) {for (i = 0; i < Accounts.num_accounts; i++) {AccountId id; id.m_number = i;AccountId id; id.m_number = i;AccountData rec = (AccountData)ac[ id ]; AccountData rec = (AccountData)ac[ id ]; rec.Balance-=10;rec.Balance-=10;ac[ id ]=rec;ac[ id ]=rec;
}}iterations += i;iterations += i;
} while (Environment.TickCount - start < 1000);} while (Environment.TickCount - start < 1000);
Common Language RuntimeCommon Language RuntimeSample Code: Value Types and boxing Sample Code: Value Types and boxing
public struct AccountId {public struct AccountId { public int m_number;public int m_number; public override int GetHashCode() public override int GetHashCode()
{ return m_number; }{ return m_number; }}}
public interface IAccountData { public interface IAccountData { int Balance{get; set;}int Balance{get; set;}}}
public struct AccountData : IAccountData {public struct AccountData : IAccountData { private int m_balance;private int m_balance; public int Balance {public int Balance {
get {return m_balance;} get {return m_balance;} set {m_balance=value;}set {m_balance=value;}
}}}}
public class Accounts {public class Accounts { public const int num = 10000;public const int num = 10000; IAccountData[] accounts = new IAccountData[] accounts = new
IAccountData[num];IAccountData[num]; public IAccountData this[Object id] {public IAccountData this[Object id] { get {return _accounts[id.GetHashCode()];}get {return _accounts[id.GetHashCode()];} set {_accounts[id.GetHashCode()] = value;}set {_accounts[id.GetHashCode()] = value;} }}}}
public struct AccountId{public struct AccountId{
public int m_number;public int m_number;
public override int GetHashCode() public override int GetHashCode()
{return m_number;}{return m_number;}
}}
public struct AccountData {public struct AccountData {
private int m_balance;private int m_balance;
public int Balance {public int Balance {
get {return m_balance;}get {return m_balance;}
set {m_balance=value;} set {m_balance=value;}
}}
}}
public class Accounts {public class Accounts {
public const int num = 10000;public const int num = 10000;
AccountData[] accounts = new AccountData[] accounts = new AccountData[num];AccountData[num];
public AccountData this[AccountId id] {public AccountData this[AccountId id] {
get {return accounts[id.GetHashCode()];}get {return accounts[id.GetHashCode()];}
set {accounts[id.GetHashCode()] = value;}set {accounts[id.GetHashCode()] = value;}
}}
}}
0.15M iter/sec0.15M iter/sec
Boxed value types 4138460Boxed value types 4138460Garbage Collections (GC) 4 Garbage Collections (GC) 4 Bytes Collected By GC Bytes Collected By GC 41384604138460GC Latency TimeGC Latency Time 132 ms 132 ms
2.5M iter/sec2.5M iter/sec
Boxed value types 2Boxed value types 2Garbage Collections (GC) 0 Garbage Collections (GC) 0 Bytes Collected By GC 0Bytes Collected By GC 0GC Latency TimeGC Latency Time 0 ms 0 ms
Common Language RuntimeCommon Language RuntimeSample Code: GenericsSample Code: Genericspublic class Accounts<U, V>public class Accounts<U, V>{{
public const int num_accounts = 10000;public const int num_accounts = 10000;private U[] accounts = new U[num_accounts];private U[] accounts = new U[num_accounts];public U this[V id] {public U this[V id] {
get {return accounts[id.GetHashCode()];}get {return accounts[id.GetHashCode()];}set {accounts[id.GetHashCode()] = value;}set {accounts[id.GetHashCode()] = value;}
}}}}
Accounts<AccountData, AccountId> ac = new Accounts<AccountData, AccountId>();Accounts<AccountData, AccountId> ac = new Accounts<AccountData, AccountId>();int i;int i;for (i = 0; i < Accounts<AccountData, AccountId>.num_accounts; i++) {for (i = 0; i < Accounts<AccountData, AccountId>.num_accounts; i++) {
AccountData rec = new AccountData(); rec.Balance = 100;AccountData rec = new AccountData(); rec.Balance = 100;AccountId id; id.m_number = i;AccountId id; id.m_number = i;ac[id] = rec;ac[id] = rec;
}}long iterations = 0; long start = Environment.TickCount;long iterations = 0; long start = Environment.TickCount;do {do { for (i = 0; i < Accounts<AccountData, AccountId>.num_accounts; i++) {for (i = 0; i < Accounts<AccountData, AccountId>.num_accounts; i++) {
AccountId id; id.m_number = i; AccountData rec = (AccountData)ac[id]; AccountId id; id.m_number = i; AccountData rec = (AccountData)ac[id]; rec.Balance-=10; ac[id]=rec;rec.Balance-=10; ac[id]=rec;
}} iterations += i;iterations += i;} while (Environment.TickCount - start < 1000);} while (Environment.TickCount - start < 1000);
Common Language RuntimeCommon Language RuntimeSample Code: GenericsSample Code: Genericspublic class Accounts<U, V>public class Accounts<U, V>{{
public const int num_accounts = 10000;public const int num_accounts = 10000;private U[] accounts = new U[num_accounts];private U[] accounts = new U[num_accounts];public U this[V id] {public U this[V id] {
get {return get {return accounts[id.GetHashCode()];}accounts[id.GetHashCode()];}
set {accounts[id.GetHashCode()] = set {accounts[id.GetHashCode()] = value;}value;}
}}}}
Accounts<AccountData, AccountId> ac = new Accounts<AccountData, AccountId>();int i;for (i = 0; i < Accounts<AccountData, AccountId>.num_accounts; i++) {
AccountData rec = new AccountData(); rec.Balance = 100;AccountId id; id.m_number = i;ac[id] = rec;
}long iterations = 0; long start = Environment.TickCount;do { for (i = 0; i < Accounts<AccountData, AccountId>.num_accounts; i++) {
AccountId id; id.m_number = i; AccountData rec = (AccountData)ac[id]; rec.Balance-=10; ac[id]=rec; } iterations += i;} while (Environment.TickCount - start < 1000);
Untyped Untyped 0.15M iter/sec 0.15M iter/sec
Strongly typed 2.5M iter/secStrongly typed 2.5M iter/sec
Generic Generic 2.5M iter/sec 2.5M iter/sec
counter total last datum n mean min maxTotal Program Run Time (ms) 11843 - - - - -App Domains Created 1 - - - - -App Domains Unloaded 1 - - - - -Assemblies Loaded 2 - - - - -Classes Loaded 175 - - - - -Methods Loaded 198 - - - - -Closed Types Loaded 0 - - - - -Closed Types Loaded per Definition 0 0 0 0 0 0Open Types Loaded 0 - - - - -Closed Methods Loaded 0 - - - - -Closed Methods Loaded per Definition 0 0 0 0 0 0Open Methods Loaded 0 - - - - -Threads in Thread Pool - 0 2 0 0 1Pending Timers - 0 2 0 0 1Scheduled Timers 1 - - - - -Timers Delayed by Thread Pool Limit 0 - - - - -Work Items Queued 1 - - - - -Uncontested Monitor.Enter Calls 2 - - - - -Contested Monitor.Enter Calls 0 - - - - -Peak Bytes Allocated (native + managed) 3326004 - - - - -Managed Objects Allocated 60266 - - - - -Managed Bytes Allocated 5801679432 28 60266 96267 8 580020Managed String Objects Allocated 20041 - - - - -Bytes of String Objects Allocated 5800480578 - - - - -Garbage Collections (GC) 4912 - - - - -Bytes Collected By GC 5918699036 1160076 4912 1204946 597824 1572512Managed Bytes In Use After GC - 580752 4912 381831 8364 580752Total Bytes In Use After GC - 1810560 4912 1611885 1097856 1810560GC Compactions 0 - - - - -Code Pitchings 0 - - - - -Calls to GC.Collect 0 - - - - -GC Latency Time (ms) 686 0 4912 0 0 16Pinned Objects 0 - - - - -Objects Moved by Compactor 0 - - - - -Objects Not Moved by Compactor 0 - - - - -Objects Finalized 1 - - - - -Boxed Value Types 3 - - - - -Process Heap - 278 235 2352 68 8733Short Term Heap - 0 278 986 0 10424JIT Heap - 0 360 12103 0 24444App Domain Heap - 0 1341 46799 0 64562GC Heap - 0 35524 2095727 0 3276800Native Bytes Jitted 22427 140 98 228 68 1367Methods Jitted 98 - - - - -Bytes Pitched 0 0 0 0 0 0Methods Pitched 0 - - - - -Method Pitch Latency Time (ms) 0 0 0 0 0 0Exceptions Thrown 0 - - - - -Platform Invoke Calls 0 - - - - -
.stat.stat
Boxed value types 2Boxed value types 2Garbage Collections (GC) 0 Garbage Collections (GC) 0 Bytes Collected By GC 0Bytes Collected By GC 0GC Latency TimeGC Latency Time 0 ms 0 ms
Closed Types Loaded 1 Closed Types Loaded 1 Closed Types per definition mean=1 max=1Closed Types per definition mean=1 max=1
Common Language RuntimeCommon Language RuntimeGenericsGenerics
Fully specialized implementation in .NET Fully specialized implementation in .NET Compact Framework v2Compact Framework v2
ProsProsStrongly typedStrongly typed
No unnecessary boxing and type castsNo unnecessary boxing and type casts
Specialized code is more efficient than sharedSpecialized code is more efficient than shared
ConsConsInternal execution engine data structures and JIT-Internal execution engine data structures and JIT-compiled code aren’t sharedcompiled code aren’t shared
List<int>, List<string>, List<MyType>List<int>, List<string>, List<MyType>
http://blogs.msdn.com/romanbat/archive/2005/01/0http://blogs.msdn.com/romanbat/archive/2005/01/06/348114.aspx6/348114.aspx
Common Language RuntimeCommon Language RuntimeFinalization and DisposeFinalization and Dispose
Cost of finalizersCost of finalizersNon-deterministic cleanupNon-deterministic cleanup
Extends lifetime of objectExtends lifetime of object
In general, rely on GC for automatic memory cleanupIn general, rely on GC for automatic memory cleanup
The exceptions to the rule…The exceptions to the rule…If your object contains an unmanaged resource that the GC If your object contains an unmanaged resource that the GC is unaware of, you is unaware of, you need need to implement a finalizerto implement a finalizer
Also implement Also implement DisposeDispose pattern to release unmanaged resource pattern to release unmanaged resource in deterministic mannerin deterministic manner
Dispose Dispose method should suppress finalizationmethod should suppress finalization
If the object you are using implements If the object you are using implements DisposeDispose, call it when , call it when you are done with the objectyou are done with the object
Assumes an unmanaged resource in the object chainAssumes an unmanaged resource in the object chain
Common Language RuntimeCommon Language RuntimeSample Code: Finalization and Dispose Sample Code: Finalization and Dispose class SerialPort : IDisposable { IntPtr SerialPortHandle;
public SerialPort(String name) { // Platform invoke to native code to open serial port SerialPortHandle = SerialOpen(name); }
~SerialPort() { // Platform invoke to native code to close serial port SerialClose(SerialPortHandle); }
public void Dispose() { // Platform invoke to native code to close serial port SerialClose(SerialPortHandle); GC.SuppressFinalize(this); }}
Common Language RuntimeCommon Language RuntimeSample Code: Finalization and DisposeSample Code: Finalization and Dispose
class SerialTrace : IDisposable { SerialPort serialPort;
public SerialTrace() { serialPort = new SerialPort(); }
public void Dispose() { serialPort.Dispose(); }}
Common Language RuntimeCommon Language RuntimeExceptionsExceptions
Exceptions are cheap…until you throwExceptions are cheap…until you throwThrow exceptions in exceptional Throw exceptions in exceptional circumstancescircumstancesDo not use exceptions for normal Do not use exceptions for normal flow controlflow controlUse performance counters to track the Use performance counters to track the number of exceptions thrownnumber of exceptions thrownReplace “On Error/Goto” with Replace “On Error/Goto” with “Try/Catch/Finally” in Microsoft Visual “Try/Catch/Finally” in Microsoft Visual BasicBasic®® .NET .NET
Common Language RuntimeCommon Language RuntimeReflectionReflection
Reflection can be expensiveReflection can be expensiveReflection performance costReflection performance cost
Type comparisons (for example: typeof() )Type comparisons (for example: typeof() )Member enumerations (for example: Type.GetFields())Member enumerations (for example: Type.GetFields())Member access (for example: Type.InvokeMember())Member access (for example: Type.InvokeMember())Think ~10-100x slowerThink ~10-100x slower
Working set costWorking set costRuntime data structures Runtime data structures
Think ~100 bytes per loaded type, ~80 bytes per loaded methodThink ~100 bytes per loaded type, ~80 bytes per loaded method
Be aware of APIs that use reflection as a side effectBe aware of APIs that use reflection as a side effectOverride Override
Object.ToString() Object.ToString() GetHashCode() and Equals() (for value types)GetHashCode() and Equals() (for value types)
Common Language RuntimeCommon Language RuntimeBuilding a Cost Model for Managed MathBuilding a Cost Model for Managed Math
Math performanceMath performance32 bit integers: Similar to native math32 bit integers: Similar to native math
64 bit integers: ~5-10X cost of native math64 bit integers: ~5-10X cost of native math
Floating point: Similar to native mathFloating point: Similar to native mathARM processors do not have FPU ARM processors do not have FPU
FXFX
.NET Compact Framework.NET Compact Framework
CLRCLR
Windows CEWindows CE
GlobalizationGlobalization GUIGUINetNetI/OI/OCryptoCrypto
System.System.GlobalizationGlobalization
System.System.CryptographyCryptography
System.System.IO.PortsIO.Ports
Microsoft.Microsoft.Win32.RegistryWin32.Registry
System.IO.System.IO.FileFile
System.System.DataData
System.XmlSystem.Xml
SystemSystem
mscorlibmscorlib
Microsoft.Microsoft.VisualBasicVisualBasic
JIT CompilerJIT Compiler& GC& GC
DebuggerDebugger
ClassClassLoaderLoader
AssemblyAssemblyCacheCache
NativeNativeInteropInterop
App DomainApp DomainLoaderLoader
ProcessProcessLoaderLoader
Memory and Memory and ThreadingThreading
File MappingFile MappingCert/SecurityCert/SecurityVerificationVerification
System.System.WebServicesWebServices
System.Net.System.Net.Http*Http*
System.Net.System.Net.SocketsSockets
DirectX.DirectX.DirectD3DMDirectD3DM
Windows.Windows.FormsForms
System.System.DrawingDrawing
SSLSSL
SocketsSockets
NTLMNTLM
GDI/GWESGDI/GWES
CommonCommonControlsControls
RegistryRegistry
File I/OFile I/O
EncodingsEncodings
SortingSorting Crypto APICrypto API
CalendarCalendarDataData
CultureCultureDataData
RedistRedist
HostHost
Visual StudioVisual Studio
Debug EngineDebug Engine
ICorDbgICorDbg
Managed LoaderManaged Loader
MSI SetupMSI Setup(ActiveSync)(ActiveSync)
Per Device CABPer Device CABInstall (SMS, etc)Install (SMS, etc)
System.System.ReflectionReflection
CasingCasing D3DMD3DM
Base Class LibraryBase Class LibraryCollectionsCollections
Pre-size collection classes appropriatelyPre-size collection classes appropriatelyResizing creates unnecessary copiesResizing creates unnecessary copies
Beware of foreach overhead, use indexer Beware of foreach overhead, use indexer when availablewhen available
ArrayList al = new ArrayList(string_array);ArrayList al = new ArrayList(string_array); foreach (MyType mt in al){//do something;}foreach (MyType mt in al){//do something;} will be compiled into:will be compiled into: callvirt instance class callvirt instance class
IEnumerator::GetEnumerator()IEnumerator::GetEnumerator() … … callvirt instance object callvirt instance object
IEnumerator::get_Current()IEnumerator::get_Current() … … callvirt instance bool callvirt instance bool
IEnumerator::MoveNext()IEnumerator::MoveNext()
Windows FormsWindows FormsBest PracticesBest Practices
Load and cache Forms in the backgroundLoad and cache Forms in the backgroundPopulate data separate from Form.Show()Populate data separate from Form.Show()
Pre-populate data, orPre-populate data, orLoad data async to Form.Show()Load data async to Form.Show()http://msdn.microsoft.com/library/default.asp?url=/library/en-us/http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfperf.aspdnnetcomp/html/netcfperf.asp
Use BeginUpdate/EndUpdate when it is availableUse BeginUpdate/EndUpdate when it is availablee.g. ListView, TreeViewe.g. ListView, TreeView
Use SuspendLayout/ResumeLayout when Use SuspendLayout/ResumeLayout when repositioning controlsrepositioning controlsKeep event handling code tightKeep event handling code tight
Process bigger operations asynchronouslyProcess bigger operations asynchronouslyBlockingBlocking in event handlers will affect UI responsiveness in event handlers will affect UI responsiveness
Form load performanceForm load performanceReduce the number of method calls during initializationReduce the number of method calls during initialization
Graphics And GamesGraphics And GamesBest PracticesBest Practices
Compose to off-screen buffers to minimize Compose to off-screen buffers to minimize direct to screen blittingdirect to screen blitting
Approximately 50% fasterApproximately 50% faster
Avoid transparent blitting in areas that Avoid transparent blitting in areas that require performancerequire performance
Approximate 1/3 speed of normal blittingApproximate 1/3 speed of normal blitting
Consider using pre-rendered images versus Consider using pre-rendered images versus using System.Drawing rendering primitivesusing System.Drawing rendering primitives
Need to measure on a case-by-case basisNeed to measure on a case-by-case basis
XMLXMLBest Practices for Managing Large XML Data FilesBest Practices for Managing Large XML Data Files
Use XMLTextReader/XMLTextWriterUse XMLTextReader/XMLTextWriter
Smaller memory footprint than using XmlDocumentSmaller memory footprint than using XmlDocument
XmlTextReader is a pull model parser which only reads a XmlTextReader is a pull model parser which only reads a “window” of the data“window” of the data
XmlDocument builds a generic, untyped object model XmlDocument builds a generic, untyped object model using a treeusing a tree
Type stored as stringType stored as string
OK to use with smaller documents (64K XML: ~0.25s)OK to use with smaller documents (64K XML: ~0.25s)
Optimize the structure of XML document Optimize the structure of XML document Use elements to groupUse elements to group
Allows use of Skip() in XmlReaderAllows use of Skip() in XmlReader
Use attributes to reduce size – processing attribute-centric Use attributes to reduce size – processing attribute-centric documents is fasterdocuments is faster Keep it short! (attribute and element names)Keep it short! (attribute and element names)
Avoid gratuitous use of white spaceAvoid gratuitous use of white space
XMLXMLCreating optimized Reader/WriterCreating optimized Reader/Writer
In v2 use XmlReader/XmlWriter factory In v2 use XmlReader/XmlWriter factory classes to create optimized reader or writerclasses to create optimized reader or writer
Applying proper XMLReaderSettings can Applying proper XMLReaderSettings can improve performanceimprove performance
XmlReaderSettings settings = new XmlReaderSettings();XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;settings.IgnoreWhitespace = true;
XmlReader reader = XmlReader.Create(“my.xml”,settings);XmlReader reader = XmlReader.Create(“my.xml”,settings);
Up to 30% performance increase when Up to 30% performance increase when IgnoreWhitespace = true is specified IgnoreWhitespace = true is specified (depends on document format)(depends on document format)
DataDataBusiness logicBusiness logicand presentationand presentation
GUI GUI
controlscontrols
In-memoryIn-memorydata copydata copy
Custom dataCustom dataStructures Structures
arrays, collectionsarrays, collectionsDataSetDataSet
SerializationSerialization Custom Custom binarybinary XmlSerializerXmlSerializer IXmlSerializableIXmlSerializable
File systemFile system
TransportsTransports Active Active SyncSync HTTPHTTP SocketsSockets ReplicationReplication
Or RDAOr RDA
Remote systemRemote system
XmlDocumentXmlDocument
BusinessBusinesslogiclogic
DataDataAdaptersAdapters
WebWebservicesservices
DataDataReadersReaders
Binary orBinary ortext filetext file
XMLXMLfilefile
SQL SQL Mobile Mobile
SQLSQLDBDB
OtherOtherDataData
Sources Sources
MSMQMSMQ
OtherOtherDBDB
Local DataLocal DataBusiness logicBusiness logicand presentationand presentation
GUI GUI
controlscontrols
In-memoryIn-memorydata copydata copy
Custom dataCustom dataStructures Structures
arrays, collectionsarrays, collectionsDataSetDataSet
SerializationSerialization Custom Custom binarybinary XmlSerializerXmlSerializer IXmlSerializableIXmlSerializable
File systemFile system Binary orBinary ortext filetext file
XMLXMLfilefile
SQL SQL MobileMobile
XMLDocumentXMLDocument
BusinessBusinesslogiclogic
SqlCeResultSetSqlCeResultSetDataReaderDataReader
Remote DataRemote DataBusiness logicBusiness logicand presentationand presentation
GUI GUI
controlscontrols
In-memoryIn-memorydata copydata copy
Custom dataCustom dataStructures Structures
arrays, collectionsarrays, collectionsDataSetDataSet
SerializationSerialization Custom Custom binarybinary XmlSerializerXmlSerializer IXmlSerializableIXmlSerializable
File systemFile system
TransportsTransports Active Active SyncSync HTTPHTTP SocketsSockets ReplicationReplication
or RDAor RDA
Remote systemRemote system
XmlDocumentXmlDocument
BusinessBusinesslogiclogic
DataDataAdaptersAdapters
WebWebservicesservices
Data Data ReadersReaders
Binary orBinary ortext filetext file
XMLXMLfilefile
SQL SQL Mobile Mobile
SQLSQLDBDB
OtherOtherData Data
SourcesSources
MSMQMSMQ
OtherOtherDBDB
Web ServicesWeb ServicesWhere is a bottleneckWhere is a bottleneck
Are you network bound or CPU bound?Are you network bound or CPU bound?Use perf counters: socket bytes sent / received Use perf counters: socket bytes sent / received Do you come close to the network capacity? Do you come close to the network capacity?
If you are network bound – work on reducing the size If you are network bound – work on reducing the size of the messageof the message
Create a “canned” message, send over HTTP; Create a “canned” message, send over HTTP; Compare performance with the web service; Compare performance with the web service;
If you are CPU bound, optimize the serialization If you are CPU bound, optimize the serialization scheme for speedscheme for speed
http://blogs.msdn.com/mikezintel/archive/2005/03http://blogs.msdn.com/mikezintel/archive/2005/03/30/403941.aspx/30/403941.aspx
Moving ForwardMoving Forward
More toolsMore toolsLive Remote Performance Counters Live Remote Performance Counters (new in v2)(new in v2)
Under construction:Under construction:Allocation profiler (CLR profiler)Allocation profiler (CLR profiler)Call profilerCall profiler
Working set improvementsWorking set improvementsMore speedMore speed
SummarySummary
Make performance a requirement Make performance a requirement and measureand measure
Understand the APIsUnderstand the APIs
Avoid unnecessary object allocation Avoid unnecessary object allocation and copies due toand copies due to
String manipulationsString manipulations
BoxingBoxing
Not pre-sized collectionsNot pre-sized collections
Performance FAQ Performance FAQ http://blogs.msdn.com/netcfteam/archive/2005/05/04http://blogs.msdn.com/netcfteam/archive/2005/05/04/414820.aspx/414820.aspx
Call To ActionCall To ActionRun your v1 applications under v2!Run your v1 applications under v2!
Backward compatibility is a key scenarioBackward compatibility is a key scenario
You know your application bestYou know your application bestConfiguration FilesConfiguration Files and Side By Side and Side By Side
Give us feedback and report bugsGive us feedback and report bugsProduct Feedback CenterProduct Feedback Center
We are performing general testing of We are performing general testing of applications we findapplications we find
400+ applications and libraries400+ applications and libraries
Get your application or library in ourGet your application or library in ourtest suite – test suite – [email protected]@microsoft.com
After The Conference…After The Conference…
DevelopDevelop
BuildBuild
InstallInstall
BuildBuild
JoinJoin
InstallInstall
EnterEnter
JoinJoin
Full-featured trial versions of Windows CE Full-featured trial versions of Windows CE and/or Windows XP Embeddedand/or Windows XP Embedded
Cool stuff & tell us about it: Cool stuff & tell us about it: msdn.microsoft.com/embedded/community
Windows Embedded Partner Program:Windows Embedded Partner Program:www.mswep.com
Windows Mobile 5.0 Eval Kit including Windows Mobile 5.0 Eval Kit including Visual Studio 2005 Beta 2Visual Studio 2005 Beta 2
Mobile2Market Contest and win up to $25000: Mobile2Market Contest and win up to $25000: mobile2marketcontest.com
Microsoft Solutions Partner Program:Microsoft Solutions Partner Program:partner.microsoft.com
Tools & ResourcesTools & Resources
msdn.microsoft.com/msdn.microsoft.com/ embeddedembedded
microsoft.public.microsoft.public. windowsxp.embeddedwindowsxp.embedded windowsce.platbuilderwindowsce.platbuilder windowsce.embedded.vcwindowsce.embedded.vc
blogs.msdn.com/blogs.msdn.com/ mikehallmikehall
Windows CE 5.0 Eval KitWindows CE 5.0 Eval KitWindows XP Embedded Eval KitWindows XP Embedded Eval Kit
msdn.microsoft.com/msdn.microsoft.com/ mobilitymobility
microsoft.public.microsoft.public. pocketpc.developer pocketpc.developer smartphone.developer smartphone.developer dotnet.framework.compactframeworkdotnet.framework.compactframework
blogs.msdn.com/blogs.msdn.com/ windowsmobilewindowsmobile vsdteamvsdteam netcfteamnetcfteam
Windows Mobile 5.0 Eval KitWindows Mobile 5.0 Eval Kit
WebsitesWebsites
NewsgroupsNewsgroups
BlogsBlogs
ToolsTools
BuildBuild DevelopDevelop