In the two previous posts, I covered the different data sources, and the impact of having a heaving OnStart event.
Today, we will look at how we can improve PowerApps Performances by taking advantage of the parallel processing functionalities available in PowerApps.
When it comes to initializing your collections of data, in most cases you would be tempted to do something like:
ClearCollect(FirstCollection, Filter(BackEndDataSource, Column1="Project 1")); ClearCollect(NewProducts, Filter(ProductsTables, ManufacturingYear=2022)); ClearCollect(ThirdCollection, Filter(BackEndDataSource2, ColumnFilter="Project 1")); ... ... ... ClearCollect(NthCollection, FirstN(BackEndDataSource, 100));
No particular issue, except that these calls will run in a sequence (sequential order), which means that the next call won’t be made until the first one completes.
This might be a problem if we are loading large data sets, and the impact of performances can be huge.
Easy, we should wrap these calls in the concurrent function, which allows us to make these calls in parallel.
Still the overall Concurrent function won’t finish until all the sub-calls have been completed. But this minor tweak will improve considerably the overall performances of your application.
Concurrent( ClearCollect(FirstCollection, Filter(BackEndDataSource, Column1="Project 1")), ClearCollect(NewProducts, Filter(ProductsTables, ManufacturingYear=2022)), ClearCollect(ThirdCollection, Filter(BackEndDataSource2, ColumnFilter="Project 1")) ..., ..., ..., ClearCollect(NthCollection, FirstN(BackEndDataSource, 100)) )
Following the same logic, when it comes to writing data to the back end (regardless of which back end you are using), the default behaviour would be to perform a series of Patches in sequence.
Here, the same problem as previously, the next write (Patch), won’t start until PowerApps Performances the previous one finishes.
ForAll( ProductsToBeUpdatedColl, Patch( Products, LookUp(Product, ID=ProductsToBeUpdatedColl[@ID]), { Name: ProductsToBeUpdatedColl[@Name], Description: ProductsToBeUpdatedColl[@Description], PPUnit: ProductsToBeUpdatedColl[@PPUnit] } ) );
Instead of looping for each item of a collection, we should make one Patch call and pass the collection to be updated as follow:
Patch( Products, ShowColumns( ProductsToBeUpdatedColl, "Name", "Description", "PPunit" ) );