36
.NET Compact Framework Performance Strategies MBL 402 Ivo Salmre Product Manager .NET Developer Technologies, UK Microsoft Corporation

NET Compact Framework Performance Strategies MBL 402 Ivo Salmre Product Manager.NET Developer Technologies, UK Microsoft Corporation

Embed Size (px)

Citation preview

.NET Compact Framework Performance Strategies

MBL 402Ivo SalmreProduct Manager.NET Developer Technologies, UKMicrosoft Corporation

Agenda

Introduction

.NET Compact Framework performance characteristics

Process for maximizing application performance

Tips and tricks

Summary

Agenda

Introduction

.NET Compact Framework performance characteristics

Process for maximizing application performance

Tips and tricks

Summary

What Is Performance?

Affected by two principlesAbsolute Performance of the system; the raw processing horsepower

Apparent Performance of the application; affected by how the application is written

Application performance is qualitatively Application performance is qualitatively measured by how responsive the measured by how responsive the application is to the end userapplication is to the end user

Key Considerations

Keep target hardware in mindThink constrained, think mobile

Use only what you really need

Where is performance important?Start-up? Data Access?

What is causing the slow down?

Does the user need to know the slow down exists?

Agenda

Introduction

.NET Compact Framework performance characteristics

Process for maximizing application performance

Tips and tricks

Summary

Performance Overview

High performing execution engine

Graphics and user interface performance

Data and XML performance

How we’re doing…

Test Tech Preview

Today

Rectangles/sec 70 749

Ellipses/sec 61 641

4-Pixel Segs/sec

63 938

Windows/sec 1.7 5.4

XMLRead/564K 161 sec 18 sec

RemoteMethod 16 sec 1 sec*Performance numbers taken using a 204 MHz, *Performance numbers taken using a 204 MHz, Strong ARM Powered PocketPC deviceStrong ARM Powered PocketPC device

We’ve come a long way, baby!We’ve come a long way, baby!

Size Data

Area Size (KB)

Execution Engine(Native Code and Binary Data) 469

Base Classes 350

WebSerices/XML 130

Drawing/Forms 190

Data (ADO.NET) 175

Visual Basic .NET Run-Time Library 56

TOTAL: 1370

*Size numbers taken on Windows CE .NET device with a Strong ARM processor*Size numbers taken on Windows CE .NET device with a Strong ARM processor

The EEA short review

Compiled managed code is a binary in Microsoft Intermediate Language

Code is just-in-time compiled to the native processor language on type-by-type, method-by-method basis

Resulting native code is cached for later reuse

Over the lifetime of the app, the up front cost of jitting is amortized, and becomes less and less significant

Code Pitching

Occurs when large volumes of allocated memory cause memory pressure

Runtime will discard or pitch code from the code cache

Qualitative inspection will tell you when this occurs

Behavior Under Memory Pressure

Memory utilizationMemory utilization

Per

form

ance

Per

form

ance

User Interface Performance

Version 1 performance is excellent!

System.Drawing and System.Windows.Forms call to native APIs beneath

Made more efficient by “batching” them where possible across the managed/native boundary

Pools and reuses Window Handles

Data And XML Performance

Version 1 performance is good

Most of stack is implemented entirely in managed code

Remember that absolute performance is affected by memory pressure

Agenda

Introduction

.NET Compact Framework performance characteristics

Process for maximizing application performance

Tips and tricks

Summary

Use Methodical Process

Analyze Performance of ApplicationDiscover where the application is slow

Choose where to optimizeWhat’s important to the customer scenarios?

Understand what the APIs are doingDoes the API do more than you need?

Different scenarios call for different performance priorities

Understand The APIs

How abstract is the API?Example: XmlDocument versus XmlTextReader/Writer

What work has to happen under the hood?

Be aware of how events fireDon’t do a lot of work in a click event if a user will be tapping and dragging object

Benchmarking Tips

Isolate exactly what is being measured

Keep microbenchmark test times > 10sec

Repeat tests 3-5 times

Ensure comparison of Apples to Apples

Use real code when possible

Test multiple designs and strategiesUnderstand the differences or variation

Perf Stats

Logged to a file on the device

nObjectsAllocated, nCurrentObjectsAllocatedCollect time is a function of current object count

nSimple/Compact/FullCollectionsMore compact full collections under memory pressure

msFullLatencyMaximum app pause due to collection

Determined by number of live objects

cbJittedNative, nMethodsJittedHow much native code is being generated?

cbPitched, nMethodsPitched More code pitched under memory pressure

Enabled via Registry Key

Alerts ClientAlerts Client

Alerts ClientOverview

AlertsDB.xml

DataSetDataSet TreeviewTreeview

ServerServer

PopulatesPopulates

PopulatesPopulates

SyncedSynced

Alerts ClientDesign strategies

DataSet.ReadXML()20 seconds total load time

XMLTextReader – Forward Data LoadingFile Read Time 6 seconds (Total: 11 seconds)

TreeView Load Time slow

XMLTextReader + Delay TreeView Population File Read Time 2 seconds (Total: 3-4 seconds)

TreeView Load Time faster

SQL Server CE + Delay TreeView PopulationQuery Time 3 seconds (Total: 3-4 seconds)

TreeView Load Time faster (same as above)

Alerts ClientDesign strategies

1. DataSet.ReadXML()20 seconds total load time

2. XMLTextReader – Forward Data LoadingFile Read Time 6 seconds (Total: 11 seconds)

TreeView Load Time slow

3. XMLTextReader + Delay TreeView Population File Read Time 2 seconds (Total: 3-4 seconds)

TreeView Load Time faster

4. SQL CE + Delay TreeView PopulationQuery Time three seconds (Total: 3-4 seconds)

TreeView Load Time faster (same as above)

Alerts ClientLessons learned

Methodical process, iterate on multiple designs

Be creative!

Understanding APIs being used

Think of the user scenarioHere, no need for user to see sub nodes of Tree

Agenda

Introduction

.NET Compact Framework performance characteristics

Process for maximizing application performance

Tips and tricks

Summary

Execution Engine

Don’t call GC.Collect()!

Minimize the number of function callsConsider making functions larger rather than having incredibly deep call stacks

Make use of asynchronous calls where useful, but avoid creating too many threads

Reduce, reuse, recycle!The less memory you allocate, the faster your app will be!

User Interface

Reduce number of method callsExample use Control.Bounds instead of Control.Location + Control.Size

Create the Window tree top down, rather than bottom up

Opposite of what VS.NET does by default

Minimize control addition on Form.Load()Defer loading of controls until they are used

Handling Data

Defer data loading until it is required, discard when data no longer in use

Minimize data in memory at any time

Forward only reading is always faster than in memory representations

XmlDocument versus XmlTextReader

DataReader versus DataAdapter

Use StringBuilder for complex string manipulations

Asynchronous Processing

Always be on the look out for asynchronous processing

Use built in asynchronous calls in network stack

Create threads to do work that can be deferred, or that shouldn’t block user interface

Network connections and data loading or synching are good candidates

Update user interface using Control.Invoke()

Let threads exitNo Thread.Abort()

Asynch Network Requests

WebService myWebService = new WebService();

IAsyncResult ar = BeginWebService(CallbackFunc, WebService);

public static void CallbackFunc(IAsyncResult Result){

WebService myService = (WebService) Result.AsyncState;object[] RemoteObjects;RemoteObjects= myService.EndGetContactList(Result);

}

Agenda

Introduction

.NET Compact Framework performance characteristics

Process for maximizing application performance

Tips and tricks

Summary

Summary

Consider your user scenario

Design, test and iterate on your design considering multiple approaches

Methodically analyze performance of your application

Understand APIs

Reduce, reuse and recycle objects

Minimize data in memory

Community Resources

Community Resourceshttp://www.microsoft.com/communities/default.mspx

Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/

NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx

User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx

Suggested Reading And Resources

The tools you need to put technology to work!The tools you need to put technology to work!

TITLETITLE AvailableAvailable

Microsoft® .NET Compact Microsoft® .NET Compact Framework (Core Reference): 0-Framework (Core Reference): 0-7356-1725-27356-1725-2 TodayToday

Microsoft Press books are 20% off at the TechEd Bookstore

Also buy any TWO Microsoft Press books and get a FREE T-Shirt

evaluationsevaluations

© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.