Reducing OnStart Load Time in Power Apps
Introduction
When a Power Apps application starts, it executes the OnStart property, which often includes tasks like loading data, initializing variables, and setting up collections. If not optimized, OnStart can significantly slow down app performance, causing delays before users can interact with the app.
In this guide, we will explore step-by-step techniques to reduce OnStart load time, improve app responsiveness, and enhance overall performance.
1. Understanding OnStart and Why It Can Be Slow
1.1 What Happens in OnStart?
The OnStart
property is executed when the app launches, and it commonly includes:
β
Loading data from SharePoint, Dataverse, SQL, or APIs.
β
Initializing variables and global collections.
β
Setting user permissions and roles.
β
Preloading images or assets.
1.2 Common Causes of Slow OnStart Load Time
π¨ Fetching too much data at once from external sources.
π¨ Multiple API calls that slow down initialization.
π¨ Using Collect()
instead of ClearCollect()
(which keeps old data in memory).
π¨ Unnecessary calculations or queries that can be deferred.
2. Optimizing OnStart Load Time
2.1 Avoid Loading Large Data Sets on Start
Instead of loading all records at once, load only the necessary data when needed.
Before (Bad Practice: Loading Everything on Start)
ClearCollect(AllOrders, Orders)
π¨ Problem: Loads all orders into memory at launch, slowing down the app.
After (Optimized: Load Minimal Data First)
ClearCollect(RecentOrders, Filter(Orders, CreatedDate >= Today() - 30))
β Loads only the last 30 days’ orders instead of everything.
2.2 Use Concurrent() to Run Functions in Parallel
Instead of running API calls one after another, use Concurrent()
to fetch multiple data sets at the same time.
Before (Sequential Calls, Slower)
ClearCollect(Users, UsersTable);
ClearCollect(Orders, OrdersTable);
ClearCollect(Products, ProductsTable)
π¨ Problem: Power Apps waits for each query to finish before starting the next.
After (Optimized: Use Concurrent for Faster Execution)
Concurrent(
ClearCollect(Users, UsersTable),
ClearCollect(Orders, OrdersTable),
ClearCollect(Products, ProductsTable)
)
β All three collections load simultaneously, cutting load time by up to 50%!
2.3 Cache Data to Reduce API Calls
If your app frequently retrieves static data, store it locally using SaveData() instead of reloading it every time.
Step 1: Save Data for Offline Use
If(IsEmpty(LocalUsers), SaveData(Users, "UsersCache"))
- Saves
Users
data locally only if it hasnβt been saved before.
Step 2: Load Cached Data Instead of Calling API
LoadData(Users, "UsersCache", true)
β This reduces API calls and speeds up app startup.
2.4 Use Lazy Loading Instead of Loading Everything on Start
Instead of fetching all data at once, load it in small chunks as needed.
Before (Bad Practice: Fetching All Data in OnStart)
ClearCollect(AllCustomers, Customers)
π¨ Problem: Fetches thousands of records before the app loads.
After (Optimized: Load Data Only When Needed)
ClearCollect(InitialCustomers, FirstN(Customers, 100))
β
Loads only the first 100 records on app start.
β
Additional records can load dynamically as the user scrolls.
2.5 Remove Unnecessary Variables & Collections
Avoid storing unnecessary data in global variables and collections, which increase memory usage.
Check and Remove Unused Variables
1οΈβ£ Go to File β Variables in Power Apps.
2οΈβ£ Identify unused global variables.
3οΈβ£ Remove unnecessary Set()
statements from OnStart
.
Example: Before (Storing Unnecessary Data in a Variable)
Set(CurrentUserData, LookUp(Users, Email = User().Email))
π¨ Problem: Loads full user data into memory even if only the name is needed.
After (Optimized: Store Only Whatβs Needed)
Set(CurrentUserName, User().FullName)
β Reduces memory usage and speeds up app launch.
2.6 Use StartScreen Instead of OnStart
Instead of executing everything in OnStart
, defer certain actions until the user reaches the relevant screen.
Step 1: Set a Default Start Screen
Go to App β StartScreen and specify which screen to load first.
Step 2: Move Non-Essential Calls to the Screenβs OnVisible Property
Screen.OnVisible = ClearCollect(RecentInvoices, Filter(Invoices, CreatedDate >= Today()-30))
β Loads data only when the user reaches that screen, instead of at startup.
2.7 Use Collections Instead of Multiple LookUps
Using LookUp()
multiple times can slow down execution. Instead, store the data in a collection and reference it.
Before (Bad Practice: Multiple LookUps in OnStart)
Set(UserRole, LookUp(UserRoles, Email = User().Email).Role)
Set(UserDepartment, LookUp(Departments, ID = UserRole.DepartmentID).Name)
π¨ Problem: Each LookUp()
query slows down execution.
After (Optimized: Store in Collection Once & Use It Later)
ClearCollect(UserData, Filter(UserRoles, Email = User().Email));
Set(UserRole, First(UserData).Role);
Set(UserDepartment, First(UserData).Department)
β Only one data call instead of multiple.
3. Best Practices for Reducing OnStart Load Time
β
Load Only Essential Data on Start β Fetch additional data only when needed.
β
Use Concurrent()
for Parallel API Calls β Reduces total wait time.
β
Cache Static Data Using SaveData()
β Reduces API calls for frequently used data.
β
Implement Lazy Loading β Load small data chunks dynamically instead of all at once.
β
Remove Unused Variables & Collections β Free up memory and improve performance.
β
Use StartScreen & OnVisible Instead of OnStart β Defer unnecessary data calls.
β
Store LookUp Data in Collections β Avoid multiple database queries.
4. Conclusion
Reducing OnStart load time in Power Apps is essential for creating a fast, efficient, and responsive app. By optimizing API calls, using lazy loading, caching static data, and running queries in parallel, you can significantly reduce app launch time and enhance the user experience.
Would you like specific optimizations for SharePoint, Dataverse, or SQL Server?