c++/cx patterns for performance
DESCRIPTION
C++/CX Patterns for Performance. Sridhar Madhugiri Principal Development Engineer 3-308. Motivation. Performance investigation of store applications in CX Internal Apps | Samples | Customer feedback Unanticipated patterns detrimental to performance - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/1.jpg)
![Page 2: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/2.jpg)
C++/CX Patterns for Performance
Sridhar MadhugiriPrincipal Development Engineer3-308
![Page 3: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/3.jpg)
MotivationPerformance investigation of store applications in CX
Internal Apps | Samples | Customer feedback
Unanticipated patterns detrimental to performance
Some parts critical for application responsiveness
![Page 4: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/4.jpg)
1. Know your boundaries2. String theory3. collections and Collections4. Who are you calling?5. “class” for app logic6. XAML data binding
Agenda
![Page 5: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/5.jpg)
1. Know your boundaries
![Page 6: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/6.jpg)
Input
Boundary
Output
Logic
![Page 7: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/7.jpg)
Boundary
InputUser | OS
Output
Application Logic
Data
Tr
ansf
orm
atio
nDa
ta C
opy
Type
Con
vers
ionDa
ta
Tran
sfor
mat
ion
Data
Cop
y
Type
Con
vers
ion
![Page 8: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/8.jpg)
Guidelines✔ Reduce number of calls across the boundary
✔ Use algorithms that do not require data copy
✔ Reduce type conversions
![Page 9: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/9.jpg)
2. String theory
![Page 10: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/10.jpg)
Platform::String ↔ C++ string typesDuplication due to type conversion
Platform::String^ → std::wstringwchar_t*, wstring → Platform::String^
Duplication overheadAllocation | Copy | Memory usage!
![Page 11: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/11.jpg)
String demo
![Page 12: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/12.jpg)
Guidelines✔ Use C++ types as string builder
✔ Use String^ iterators to inter-op with STL
✔ Use String^ iterators to inter-op with application logic
✔ Use String^ for pass through strings
✔ Use StringReference for “IN” parameters
![Page 13: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/13.jpg)
3. collections and Collections
![Page 14: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/14.jpg)
WinRT collections
Change triggers notificationInsertion | Deletion | Element change
Element accessVirtual call across boundary | Out of bounds check
Implication becomes obvious as collection size scales
!
!
![Page 15: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/15.jpg)
Collections demo
![Page 16: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/16.jpg)
Guidelines✔ Use in std::vector for initial population
✔ Use ReplaceAll
✔ Use GetMany
![Page 17: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/17.jpg)
4. Who are you calling?
![Page 18: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/18.jpg)
Casts
Implicit CastInvoking member on non-default interfaceInvoking member of an interface required by “I”Function arguments
Cast is QueryInterfaceVirtual call | Interlocked operation!
![Page 19: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/19.jpg)
Cast demo
![Page 20: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/20.jpg)
Guidelines✔ Optimizer will optimize casts but not on escaped variables
Global | Member variable | Address taken
✔ Use local variables to optimize redundant casts
!
![Page 21: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/21.jpg)
5. “class” for app logic
![Page 22: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/22.jpg)
class vs. ref classC++ classes give flexibility
Instance on stack, unique ownership, shared ownership
R^ is equivalent to shared_ptr<N>“this” for ref class is equivalent to shared_ptr<N>Overhead similar to using shared_ptr<N>
![Page 23: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/23.jpg)
Guidelines✔ Use stack allocation or unique_ptr
✔ Use shared_ptr for shared ownership
✔ Use ref classes for interaction with boundary
![Page 24: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/24.jpg)
6. XAML data binding
![Page 25: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/25.jpg)
Guidelines✔ Implement INotifyPropertyChange only when required
✔ Implement only public property getterPublic setter required if UI modifies value
✔ Keep data model hierarchy shallow
✔ Minimize cost to satisfy data request from XAML
![Page 26: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/26.jpg)
//build/ talks related to performance2-192 Building a UI: What Does it Cost?
Chris Anderson
3-157 XAML Performance FundamentalsKiran Kumar
3-158 Dramatically Increase Performance when Users Interact with Large Amounts of Data in GridView and ListView
Chipalo Street
3-099 App Performance: From UX to API for 5 Key ScenariosJason Hendrickson
![Page 27: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/27.jpg)
SummaryWinRT presents a new boundary with unique issues
Measure and understand the performance bottlenecks
Use guidelines and patterns to help with productivity, correctness and performance
![Page 28: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/28.jpg)
What?• Are you interested
in having an impact on the future user experiences in Visual Studio? Come help us shape the future.
Give us your feedback!When & Where?• Participant in
ongoing feedback sessions
• Send us an email [email protected]
Why?• Your input and
feedback will influence future Microsoft Visual Studio tools
![Page 29: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/29.jpg)
Q & A
Sridhar Madhugirisridmad at Microsoft dot com
![Page 30: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/30.jpg)
Evaluate this session
Scan this QR code to evaluate this session and be automatically entered in a drawing to win a prize!
![Page 31: C++/CX Patterns for Performance](https://reader036.vdocument.in/reader036/viewer/2022081511/56815fdd550346895dcee6d9/html5/thumbnails/31.jpg)
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.