Download - 94% of apps peak at
![Page 1: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/1.jpg)
Andrew WhitechapelProgram ManagerMemory and CPU Policy in Univeral Apps
Expand Your Reach by Tuning for Memory and CPU Policies
3-91
![Page 2: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/2.jpg)
Why do I care?What does policy cover?Why does the system do this?How does policy vary per SKU or device?Show me the code
Agenda slide
![Page 3: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/3.jpg)
• I can make my app scale across multiple devices and SKUs
• I can make my app resilient to ongoing conditions• Hardware, connectivity, state changes
• My app doesn’t show up on the battery wall of shame
• My app doesn’t crash or cause the device to become unusable
• I can use a rich set of features without degrading the system
Why do I care?
![Page 4: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/4.jpg)
• Resources are finite• Maintaining an optimal balance• Different strokes for different task types• Mapping scenario priority to resource
sets• Achieving predictability• Allow apps to understand and
cooperate in the running ecosystem• Adjusting dynamically
Why does the system do this?
![Page 5: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/5.jpg)
• Policy is holistic• Memory• CPU and task lifetime• User expectations and scenario
prioritization• Gated access to sensors• Other constraints
What does policy cover?
![Page 6: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/6.jpg)
Memory breakdown examples 94% of apps
peak at <150MB.
92% of apps average at <100MB.
Component usage (ballpark)512MB Phone
1GB Tablet
2GB Desktop
Total physical 512 1024 2048
Paging level 200 200 1600
712 1224 3648
BSP, OS, drivers, services 425 425 425
OEM/MO service agents 22 40
VOIP or Background audio 66 80 80
VPN 10 10 20
523 555 525
Foreground App 185 390 900Back-stack, Task completion, BG tasks, More FG apps 4 279 2223
![Page 7: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/7.jpg)
Different strokes
Task typeMemory Cap MB
Lifetime CPU
Block in Batt-Sav
Default Background Task 16 30 sec 10% Y
Long-Running Bluetooth 16 ∞ 10% Y
Extended Execution 150 10 min 10% YBackground Audio Playback 25 ∞ 10% N
VOIP Active Call 66 ∞ 70% N
Modern Foreground App 185 ∞ 70% N
Example: 512MB
device
![Page 8: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/8.jpg)
• Scenario-based prioritization.
Task Priorities
*Higher priority if part of the Foreground experience.
Task type Priority
Foreground App 2
VOIP 2
Background Audio 2
VPN 2
Background Transfer 2 or 6*
Bluetooth 3CachedFileUpdater/ShareDataPackage Task 3 or 6*
Task Completion 4
Geofence-triggered Task 5
Default Background Tasks 6
App in the backstack 7
![Page 9: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/9.jpg)
Example: Background Audio Agent
Sensor resources
Resource Allowed?
Microphone Camera Proximity Gyro Compass Accelerometer Vibrator Push SpeechSynthesis SpeechRecognition Audio InterruptiveUI
![Page 10: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/10.jpg)
• Protected sensor resources• MemoryManager API• EnergyManager API
Show me the code
![Page 11: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/11.jpg)
Sensor Resource APIsNetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged;Battery.AggregateBattery.ReportUpdated += OnBatteryReportUpdated; ;
bool isGyro = Gyrometer.GetDefault() != null;bool isAccelero = Accelerometer.GetDefault() != null;bool isCompass = Compass.GetDefault() != null;MediaCapture mediaCapture = new MediaCapture();bool isCamera = mediaCapture != null;
BatteryReport batteryReport = Battery.AggregateBattery.GetReport();if (batteryReport.Status != BatteryStatus.NotPresent){ int charge = (int)batteryReport.RemainingCapacityInMilliwattHours;}
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();ConnectionCost cost = profile.GetConnectionCost();if (cost.Roaming || cost.OverDataLimit) ; // prompt for user opt-in.else if (cost.ApproachingDataLimit) ; // throttle behavior.
![Page 12: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/12.jpg)
MemoryManager APIsMemoryManager.AppMemoryUsageIncreased += OnAppMemoryUsageIncreased;MemoryManager.AppMemoryUsageDecreased += OnAppMemoryUsageDecreased;
ulong usageLimit = MemoryManager.AppMemoryUsageLimit;ulong usage = MemoryManager.AppMemoryUsage;ulong headroom = usageLimit - usage;
AppMemoryReport appReport = MemoryManager.GetAppMemoryReport();ulong privateCommit = appReport.PrivateCommitUsage;ulong peakPrivate = appReport.PeakPrivateCommitUsage;ulong totalCommit = appReport.TotalCommitUsage;ulong commitLimit = appReport.TotalCommitLimit;
ProcessMemoryReport processReport = MemoryManager.GetProcessMemoryReport();ulong privateSet = processReport.PrivateWorkingSetUsage;ulong totalSet = processReport.TotalWorkingSetUsage;
![Page 13: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/13.jpg)
EnergyManager APIsBackgroundEnergyManager.RecentEnergyUsageIncreased += OnRecentEnergyUsageIncreased;BackgroundEnergyManager.RecentEnergyUsageReturnedToLow += OnRecentEnergyUsageReturnedToLow;
uint usage = BackgroundEnergyManager.RecentEnergyUsage;
uint usageLevel = BackgroundEnergyManager.RecentEnergyUsageLevel;if (usageLevel == BackgroundEnergyManager.NearTerminationUsageLevel) ;// Get ready to be terminated.else if (usageLevel == BackgroundEnergyManager.ExcessiveUsageLevel) ;// Throttle back urgently.else if (usageLevel == BackgroundEnergyManager.MaxAcceptableUsageLevel) ;// On the wall of shame.else if (usageLevel == BackgroundEnergyManager.NearMaxAcceptableUsageLevel) ;// Approaching the wall of shame.else if (usageLevel == BackgroundEnergyManager.LowUsageLevel) ;// Good citizen.
![Page 14: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/14.jpg)
• Variation by SKU• Mobile vs Desktop vs HoloLens vs IoT vs Xbox
• Variation by device• Physical RAM, Pagefile, Screen resolution
• Variation by app technology• Universal apps, pre-Windows 10 Phone, pre-Windows
10 Modern Desktop, Win32
How does policy vary?
![Page 15: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/15.jpg)
• Target a wide range of SKUs and devices
• Query the system to discover your constraints
• Listen for change events• Tune your behavior accordingly
What’s the moral of the story?
![Page 16: 94% of apps peak at](https://reader036.vdocuments.mx/reader036/viewer/2022062314/56649d985503460f94a82ae2/html5/thumbnails/16.jpg)
© 2015 Microsoft Corporation. All rights reserved.