Performance tuning in Canvas Apps Power Apps using Caching & Concurrent
Canvas App changed the way we design mobile applications. We can easily configure Canvas Apps by connecting multiple data sources in a minute. But in the configuration journey we have to keep the app performance point into consideration otherwise the app performance will be very slow.
In this post I will discuss 2 important performance tuning factors.
Caching Data Sources
Very often in our canvas app we query the same data repeatedly, like in the case of pulling the lists of skills for our drop-down menus. In those scenarios, we can query for the data once and then reuse that data throughout the app which will reduce the repetitive calls to the data source across the network.
The following is an example of this scenario.
In our app, we have multiple screens where we provide a drop-down menu for selecting the skills. The list of skills is kept in Microsoft Dataverse in a table named SkillTable. On each instance of the menu, we use the following formula.
Filter(SkillTable, Status = "Active")
There is no issue in the formula but when we call this expression multiple time in our app the data load every time although the data is static so we could modify our app to create a collection with the OnStart property of the app that stores the information using the following formula.
Collect(collectSkillTable, Filter(SkillTable, Status = "Active"))
Now we can change the Items property of the drop-down controls to be collectSkillTable instead of Filter(SkillTable, Status = “Active”). These small changes add up to increase performance in our app.
Using Concurrent function to load multiple data sources
In certain scenarios we use multiple Collect statement when we want to load multiple data source the formula may look like as below:
Collect(collectSkillList, Filter(SkillList, Status =
"Active")); Collect(collectCompanyList,
CompanyList);Collect(collectRegions, RegionList)
In this example, we are creating 3 collections, but the collections are processed one at a time. So if each one takes 2 seconds to process then the users has to wait 6 seconds for the app to start.
The Concurrent function allows us to process all of those calls at the same time. We can change our code to the following.
Concurrent(
Collect(collectSkillList, Filter(SkillList, Status = "Active")),
Collect(collectCompanyList, CompanyList),
Collect(collectRegions, RegionList)
)
Now all three formulas run at the same time. Reducing your load time to 3 seconds. Concurrent is a great way to avoid long delays from asynchronous calls.
Hope this helps.
Follow my blog for more trending topics on Dynamics 365, Azure, C#, Power Portals and Power Platform. For training, Courses and consulting, call to us at +91 832 886 5778 I am working more for community to share skills in Dynamics 365 and Power Platform. Please support me by subscribing my YouTube Channel. My YouTube Channel link is this : https://www.youtube.com/user/sppmaestro