1 / 31

C++/CX Patterns for Performance

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

tanith
Download Presentation

C++/CX Patterns for Performance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++/CX Patterns for Performance Sridhar Madhugiri Principal Development Engineer 3-308

  2. Motivation • Performance investigation of store applications in CX • Internal Apps | Samples | Customer feedback • Unanticipated patterns detrimental to performance • Some parts critical for application responsiveness

  3. Agenda • 1. Know your boundaries • 2. String theory • 3. collections and Collections • 4. Who are you calling? • 5. “class” for app logic • 6. XAML data binding

  4. 1. Know your boundaries

  5. Boundary Input Logic Output

  6. Boundary Data Transformation Data Transformation Data Copy Data Copy Type Conversion Type Conversion Output Input User | OS Application Logic

  7. Guidelines • ✔ Reduce number of calls across the boundary • ✔ Use algorithms that do not require data copy • ✔ Reduce type conversions

  8. 2. String theory

  9. Platform::String ↔ C++ string types • Duplication due to type conversion • Platform::String^ → std::wstring • wchar_t*, wstring → Platform::String^ • Duplication overhead • Allocation | Copy | Memory usage !

  10. String demo

  11. 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

  12. 3. collections and Collections

  13. WinRT collections • Change triggers notification • Insertion | Deletion | Element change • Element access • Virtual call across boundary | Out of bounds check • Implication becomes obvious as collection size scales ! !

  14. Collections demo

  15. Guidelines • ✔ Use in std::vector for initial population • ✔ Use ReplaceAll • ✔ Use GetMany

  16. 4. Who are you calling?

  17. Casts • Implicit Cast • Invoking member on non-default interface • Invoking member of an interface required by “I” • Function arguments • Cast is QueryInterface • Virtual call | Interlocked operation !

  18. Cast demo

  19. Guidelines • ✔ Optimizer will optimize casts but not on escaped variables Global | Member variable | Address taken • ✔ Use local variables to optimize redundant casts !

  20. 5. “class” for app logic

  21. class vs. ref class • C++ 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>

  22. Guidelines • ✔ Use stack allocation or unique_ptr • ✔ Use shared_ptr for shared ownership • ✔ Use ref classes for interaction with boundary

  23. 6. XAML data binding

  24. Guidelines • ✔ Implement INotifyPropertyChange only when required • ✔ Implement only public property getter Public setter required if UI modifies value • ✔ Keep data model hierarchy shallow • ✔ Minimize cost to satisfy data request from XAML

  25. //build/ talks related to performance • 2-192 Building a UI: What Does it Cost? Chris Anderson • 3-157 XAML Performance Fundamentals Kiran Kumar • 3-158Dramatically Increase Performance when Users Interact with Large Amounts of Data in GridView and ListView Chipalo Street • 3-099App Performance: From UX to API for 5 Key Scenarios Jason Hendrickson

  26. Summary • WinRT presents a new boundary with unique issues • Measure and understand the performance bottlenecks • Use guidelines and patterns to help with productivity, correctness and performance

  27. Give us your feedback! • What? • Are you interested in having an impact on the future user experiences in Visual Studio? Come help us shape the future. • When & Where? • Participant in ongoing feedback sessions • Send us an email vsdr@microsoft.com • Why? • Your input and feedback will influence future Microsoft Visual Studio tools

  28. Q & ASridhar Madhugirisridmad at Microsoft dot com

  29. Required Slide *delete this box when your slide is finalized Your MS Tag will be inserted here during the final scrub. Evaluate this session • Scan this QR codeto evaluate this session and be automatically entered in a drawing to win a prize!

More Related