Power Apps Performance Optimization Tips

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is rezab irani today's video is chapter one in my powerapps performance tips series we will look at formula level optimization and controls optimization in canvas apps we will look at how to reduce controls how to avoid multiple queries repeating formulas and much more so let's get started with the video but first my introduction [Music] the first tip on powerapps performance is around the usage of a function called the concurrent function and what this function allows us to do is it allows us to execute multiple functions concurrently as against running them one after the other now on this screen i have a couple of buttons one wherein i run my actions sequentially so if you look at the formula for this button on select of this button i'm first setting a few variables to track the start time and then once all the functions are executed here i'm setting the end time and then calculating the difference in duration so that we can see how long the execution of the functions in between these actions takes i'm basically going ahead and querying my data source in this case my data source is a list of students this list has more than 5000 records now in my app i am executing five queries here and creating five different collections storing the information of students whose names begin with the letters a b c d or e it's just a demo use case here on the other side i have the concurrent function which is basically more or less executing the same actions but the only difference here is when i'm querying my data source and creating those five collections again this time i'm running all my actions inside a function called concurrent and what concurrent allows me to do is to run all of these actions together now i will click on the sequential button let's see how long it takes for the actions in this function to execute so right now this action took 4.7 seconds to execute those five queries against my data set that has over 5000 records on the other side now i will try and execute those same actions but this time in the concurrent function and if you observe right here i received the response in 1.1 seconds if you look at the images that i have provided here on top these are just sample illustrations right here when you execute functions sequentially which is the standard case of writing functions in powerapps each and every function that you write would be executed sequentially so for example the first function gets executed then it moves to the second one then to the third one and so and so forth and that's the reason why this action took approximately 4.7 seconds in my scenario whereas if i execute those same actions inside a concurrent function if you notice powerapps will create these multiple threads and it will basically start executing all those actions concurrently and that is the reason why there is a game right here in performance now where should i be using concurrent wherever you have scenarios wherein you're adding multiple functions and if you can fire all those functions concurrently then go ahead and use this function one common scenario is the app.onstart function and this function is the function that gets called when the app loads the first time for a user session and this is the ideal function to execute any actions or queries that you need before the user navigates to the main screen so right now in this example i have a collection that is basically generating my left hand navigation menu right here i'm querying my data source and adding it into a collection and i have some other branding functions that i'm calling here so these functions here are not dependent upon each other so what i can do right here is go ahead and call the concurrent function and right here where my first function execution completes i will put a comma so i have my second formula put a comma that's my third formula and finally this is my last formula and i will go ahead and close the entire concurrent function i will format the text so i can see all these functions are now being executed inside the concurrent function all of these functions now will run concurrently and the performance of my app load time would increase significantly key thing to understand about the concurrent function is it runs things concurrently so if you're writing multiple functions and a function is dependent upon the output of a previous function in that case do not use concurrent the next performance tip is around controls optimization and dependency now the recommendation is that in your power app you should not have in total more than 500 controls across all your screens now if you take this screen as an example my controls optimization screen these are the controls that i have added in here now let's take a very simple use case i need a tab like experience for my users and very common cases we go ahead and we add buttons to create that tab like experience and right here i have created five button controls to create that tab like experience the goal here is to reduce controls to keep our control count to a minimum one of the key controls is the gallery control whenever you come across scenarios that are repeating you need to think about the gallery control in this case i've added five button controls for the tab lag experience but i can also replace that with a gallery control that has a single button control in it and the beauty of a gallery is in the items property i can provided a collection of data in my case i've just gone ahead and hard coded the names of my tabs and right here i have exactly the same experience as my five button controls but the key difference is that in the second scenario i just have two controls my gallery control and my button control as against my five controls that i have added on the top another key aspect is components components allow us to build these reusable controls that we can leverage across screens in this app right here i have two examples of components i have a header component right here and on the left hand side i have a menu component now if you look at my screen in this case on the left hand side is just a single control it's my menu component control now if you look at my header i have a label control and i have the image right here those are two controls but i have gone ahead and created a component for my header control now if i head back to my screen and if i remove both of these controls i can easily replace this with my header component and this component has a property to set the header text i've just gone ahead and set that and just like that i have replaced two controls in my header with a single control which is my header component now if you look at my components my components has those two controls right here but when i add them to my screen i just have to add a single control now think about the left hand side navigation component in this case i have multiple screens and each of these screens has the left hand side navigation component now if i was to go ahead and create for example a button like experience for this imagine the number of controls i would have had to create for each and every screen just to add this experience on the left hand side so to enable reusability i just went ahead and created a very simple menu component and guess what the component uses a gallery why because even the menu items are repeating so i've just created a very simple gallery that has these additional controls so if you think about it i have five controls inside the gallery the gallery itself so that's six controls and when i'm adding this component to a screen that's just a single control that i'm adding right here as my component another key feature around control optimization is around the text input control now a text input control has a property called delay output and as you can see in my case here it is set to false now if i preview the app i have this text control here and i have a label control that basically prints the value in the text control so i will go ahead and type my name and observe as i type basically each keystroke that i make on the right hand side the label control is immediately showcasing me the value however if i go ahead and set delayed output to true and if i preview this and let's say i replace my text now observe as i type once i pause only then the value will be showcased in that label control basically the text control is delaying its output so what's the advantage of this well let's take an example of a scenario right here i have a gallery that is connected to my same data source my students list and right here i can search the student's name so let's say i search for james so this is going to return all my students whose names begin with james but let's try this again i will type each letter and observe as i start typing it's actually querying my data source every keystroke it is squaring my data source think about this i just typed five letters right here those are five queries that are being executed against my back-end data source think about the performance hit in this case would i not want the user to go ahead and basically plug in all the keystrokes and only then query my data source well for that all i have to do is just go ahead and for this text control search for the delay output property and turn this to true now if i go ahead and preview this app observe as i start typing it's not querying now when i stop it makes the query against my data source that's just one query against my data source and giving the user the desired output it's a very minor change but it can have a massive impact on performance another piece around controls is something known as control dependency i have two simple label controls and if you observe the color of these label controls they are both purple however from a performance standpoint how i set the value of this color also makes a difference now for the first label here if i look at the color property the value of this color property is coming from another label called lbl gal count dot color so i'm basically referencing a control in a different screen and that is basically my home screen right here this is that control called lbl galcon now this has that color which is purple and for my controls optimization screen i'm referring to a control that is in a different screen what's the problem well the problem is when powerapps loads a screen it only loads the controls within that screen to optimize performance but if any control in your current screen references any other control in a different screen in that case powerapps will load all the controls in that different screen as well so in this case powerapps will load all the controls in my controls optimization screen and because for this label controls color property i'm referencing a control that's in a different screen it will also go ahead and load all the controls of this screen and memory and that also decreases performance so how do i get around this well use variables so in this case if you look at my second variable here if i look at the color property this property is being set from a variable and where am i creating this variable i'm creating this variable on the start of my app and this also helps me in consistency in branding on the app start i've created a variable where i'm defining that purple label color right here so the output is the same but because i'm just referencing a variable and a global variable which is already held in memory power apps can quickly grab that and it will not load other controls from other screens in memory i'll give you a very common use case something that i have also done as part of my demos but those demos were for illustration purposes only the gallery control and the form control many times we have a gallery control that's connected to a form control in a different screen the item property of that form control is set to gallery dot selected but gallery is in a different screen so what power apps will do it will load all the controls of that different screen in memory as well and how do i avoid that well when you navigate from your gallery screen to the form screen ensure that you set a variable to the context of that gallery item so that you can use it in your form screen and there is no control dependency the next step is around something known as the n is to one query now a gallery is a collection of data and i can have as many items that number is represented as n i have a very simple gallery right here that is basically showing me all the data from my students list and in this gallery i have label control that i have added right here and what this label control does is it goes ahead and performs a query against a different list so if you look at this this is querying another list called class if you look at my data source i've even connected to that list and this is what the list looks like it's a simple list of classes and who are the teachers for that class and every student has an association with the class but what i needed in my gallery is the name of the teacher as well so what i ended up doing is this i just created a very simple function that says look up my class list and for the current class of the student go and grab the teacher's name and if i preview this it's working fine it's giving me all the names of the teachers for the respective students however there is a big problem for every item in this gallery it is basically firing an additional query a query against another list just imagine the number of items in the gallery and as i keep scrolling down the gallery will keep loading data in memory in an optimized manner as long as my query is delegable and it is querying all that data that's a lot of queries against your data source that's going to impact performance big time so how do i avoid this my secondary list has the information right here so instead of querying this list if i can query a collection that has the same data as the list that would be a lot faster and i'm not querying my data source i'm basically querying a local collection that is created in powerapps and where do i create that collection well once again on the onstart function of my app right here all i have done is created a very simple collection that has its data coming from that same list which is my class list and now if i head back to that label control instead of querying directly my data source why not replace this with that collection which is held locally in memory this will now query that local data source which in turn will give you a massive gain in performance next tip is around the formula level optimization now very common function that i have seen in a lot of apps and specifically i have seen a lot of questions on the community forum that actually includes this function is the usage of first filter so in this case here i have a formula right here that says go and filter the students list where the name of the student begins with david and then get me the first student and get that student's bio information now there are two problems here the first problem is the usage of the function first first is not delegateable against my data source that means it will not give me accurate results if my data source spans beyond 2000 records also even if my data source is less than 2000 records because this function is not delegable powerapps will load all the data in memory and then perform the query and that is going to impact performance and second if my data is beyond 2000 records depending upon the delegation limit that i've set in my app the max limit is 2000 in that case i may get false positive results so instead of first filter all i have done right here is replaced it with the lookup function and the output here in this case is exactly the same but there are two key differences one delegation if you note i am not getting a delegation error right here so this will work with large data sets and second the lookup function only returns a record if you look here the data type that it returns is a record so it only gets me one item whereas if i look at the filter function this function returns a table a collection and because i just need the first record we go ahead and execute the first function to give us that record but that's a big problem think about this now let's take a very simple example i have 500 records in my data source and i'm applying this filter function to search for david and let's say the student name david is sitting at position number 50. so this query will find david it will add it to its table and that's all i need i just need the first value in that table but guess what the formula is designed for it's designed to return tabular data so it's going to filter the entire data set it will keep scanning the entire data set all the 500 records and get all the data and once it does that it only then it will give me the first value from it because i'm firing the first function whereas on the other hand the lookup function the moment it finds david even though my data set has 500 records let's say it found david on position 50 it will stop the query execution going forward once again giving you a massive gain in performance now let's look at an example of repeating formulas so in this case i have a very simple form which basically fills the current logged in user's information now in my case for the current logged in user's information on the app onstart i'm setting a variable right here which is storing the current logged in user's name and i'm using this right here to get the value of the user's name from my data source and i'm using the lookup function here to query my students list where the name of the student begins with the variable that i'm setting on app start and right here i'm getting the name of the student so it's putting the name right here i have exactly the same query and i'm getting the class the student belongs to then again exactly the same query and i'm getting the bio information of the student when the problem is that this query is repeating every time i'm firing one two three queries to get three pieces of information now rather than repeating this formula over and over again why don't i just call this formula once and where can i do that well in this case on the on visible property of this screen what i can do is just go ahead and set a very simple variable and execute that same function but just once get me the information of the current logged in user i'm storing it in a variable and now instead of querying the data source i can just directly get that value from that variable and the output would be exactly the same and all i've done right now is gone ahead and replaced all those queries with that variable that i'm setting against my data source and if you look at the output it's exactly the same so don't keep repeating the formulas over and over again if you can get the value once and just store it in a variable you can just leverage that variable and thereby you're reducing the number of network calls that you're making against your data source thereby once again improving performance so this was part one of my powerapps performance series if you did enjoy this then do like comment and subscribe to my youtube channel and don't forget to hit the bell icon so that whenever i post my latest video you get notified about thank you so much for watching
Info
Channel: Reza Dorrani
Views: 7,818
Rating: 5 out of 5
Keywords: powerapps performance, powerapps performance optimization, powerapps performance issues, powerapps performance tips, powerapps performance review, Power Apps Performance Optimization Tips, power apps performance, powerapps slow to load, powerapps slow, powerapps poor performance, optimize powerapps performance, powerapps, power apps, microsoft power apps, reza dorrani
Id: _2jDGqtqqi8
Channel Id: undefined
Length: 21min 36sec (1296 seconds)
Published: Tue Feb 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.