I have a Foreach loop in one of my Power Automate
This runs for all the rules that are defined in a SharePoint List, so it a foreach that runs on result of get list items.
Currently the list has around 300+ rules defined in it. Initially the Foreach loop took around 8 minutes to complete and after I turned on the concurrency and set it to 50, it came down to around 1 minute
If this list grows to 2000+ items in the future, this foreach loop might take 4-5 minutes.
Is there any other way to improve the speed of Foreach? can we change the Performance Profile of the Power Automate to high so that it performs actions faster?
Hi @svignesh
If you try
if(contains(outputs('Get_file_content')?['body'],'ItemTitle'),'ItemTitle','')
into a compose you can get rid of your condition action and yes/no - will need updated with your expressions/dynamic values.
You could simply have
Equally you could have 1 append to string if the items in the rules list were fixed
Or in the above example, just use a compose - as you throw this string away and it won't be updated at all. You only need a variable if you are updating it.
This 1 expression will check for ItemTitle in the body of the file contents (or in your case the variable you set) and either output a string or nothing i.e. ''.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
P.S. take a look at my new blog here
Hello Damien,
The Power Automate is like the one below
Once for loop is over, I use the update file properties once and set the values. There will be multiple matching terms based on the rules list and all the terms will be constructed via append to string action that is inside the for each rule
Thank you for your help, really appreciate it.
Hi @svignesh
Using update file properties?
You could use an if expression and the contains expression
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
P.S. take a look at my new blog here
Thank you Damien
The flow runs against one file, whenever a file is uploaded, it gets the file content and I am setting it to a variable
Rules are defined in the SharePoint list, for instance, consider the Tag to add as a managed metadata column, the Title has the text that I am checking for in the Contains
Title Tag to add
DamoBird365 O365
SharePoint SharePoint
In this case, foreach will run 2 times
first time, it will check if the file content variable contains DamoBird365 and add O365 tag, second time it will check if the file content variable has SharePoint and add SharePoint tag
Finally after foreach completes, I update the file property with values like
O365|GUID-of-term;SharePoint|Guid-of-term
@DamoBird365 wrote:Hi @svignesh
You are reading each file? It would have an overhead alright. You mention you set the contents to a variable?
You could just use a compose to check content.
For example:
Check that file contents contain DamoBird365 using the Contains expression
This results in True
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
Hi @svignesh
You are reading each file? It would have an overhead alright. You mention you set the contents to a variable?
You could just use a compose to check content.
For example:
Check that file contents contain DamoBird365 using the Contains expression
This results in True
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
Sure Damien
I don't have much inside the foreach loop, basically I pull the file contents and set it to a variable.
Inside the Foreach,
I check if the file content variable "Contains" the text in the rule, Contains(fileContentVariable,currentItemText), and if it does I do a append string action to build metadata column based on file content
and finally after the foreach is over and the managed metadata string is built, I update the file properties with that
How weird that @jinivthakkar and I link to the same post - honestly we are not working together! 🤣 Although I guess we are as part of the community!
Hi @svignesh
I believe that the only difference is per flow or per user license - see here.
There are subtle changes you can make to a flow that improve performance. Using Compose instead of Variables (where there isn't a need to store and update a value) and using expressions to obtain a result in one action rather than many. Obviously if your apply to each has one action, there isn't much that can be improved. If you are using get items, you could of course use a filter to reduce the number of apply to each repeats you're performing or use a filter array action to similarly reduce the number of repeats.
I've never tried this myself but maybe you could split the get items into two groups (2 seperate actions or 2 seperate filters from the 1 get items action) and run the apply to each in parallel as well as the concurrency turned on for both.
If you supply more on your apply to each loop, we could make suggestions on performance improvements if you want.
Pieter Veenstra has a lot of good content on performance for you to read up on.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien
@svignesh check if this fits your solution - https://sharepains.com/2020/02/10/1-flow-performance-tip-to-get-your-flows-out-of-the-stone-age/
apart from the concurrency there is no other settings, all you could is add some filters and get less data.
--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.