web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / This onVisible screen ...
Power Apps
Answered

This onVisible screen collection takes 30 seconds to load...suggestions for improving the logic

(0) ShareShare
ReportReport
Posted on by 678

I think it's safe to agree that 30 seconds is toooo long.

I am trying to do lots of things here...
1) _c = grouping all my comments and then referencing the 1st (most recent comment) for each HotelId
2) Create a collection off the HotelRFP As _p data source that was 262 rows in it.
3) As I loop through each row I grab the most recent comment value for the specific HotelId, I grab the Status row in the RFP Lookup list for the a match on Status and also the row for the appropriate dictHotelBrand and Chain ...
4) Then lastly I patch to the collection numerous variables which in turn are also based on LookUp values from 4 other tables and the previously provided values in #1, #2 and #3.

The largest list is the main HotelRFP list with 262 rows. Suggestions for getting this down to 5 seconds runtime? I was looking in the Monitor and the last run had the ForAll taking 61,7956ms. The next closest row in monitor is 1,412 ms.

With(
 {
 _c: ForAll(
 GroupBy(
 RFPComments,
 "HotelId",
 "GroupedItems"
 ),
 With(
 {
 _top: First(
 Sort(
 GroupedItems,
 Modified,
 Descending
 )
 )
 },
 {
 HotelId: HotelId,
 MostRecentComment: _top.Modified,
 MostRecentCommentStatus: _top.Comment,
 DateCreated: _top.Modified,
 CommentWho: _top.'Modified By'.DisplayName,
 StatusId: _top.StatusId,
 CommentCount: CountRows(GroupedItems)
 }
 )
 )
 },
 ClearCollect(
 RFPListing,
 ForAll(
 HotelRFP As _p,
 With(
 
 {
 _mrc: LookUp(
 _c,
 HotelId = _p.ID
 )
 },
 With({
 _col: LookUp(
 RFPLookUp,
 ID =_mrc.StatusId
 ),
 _br: LookUp(dictHotelBrands,ID=_p.brandId),
 _ch: LookUp(dictHotelChains,ID=_p.chainId)


 },
 Patch(
 _p,
 {
 Status: _col.Title,
 StateName: LookUp(dictStates,ID=_p.stateId,stateName),
 CountryCode: LookUp(dictCountries,ID=_p.countryId,countryCode),
 ContinentCode: LookUp(dictContinents,ID=_p.continentId,continentCode),
 ChainCode: _ch.Title,
 BrandCode: _br.Title,
 ChainName: _ch.name,
 BrandName: _br.name,
 MetroCode: LookUp(ColMetrosUsed,ID=_p.metroId,metroCode),
 ColorR: _col.ColorR,
 ColorG: _col.ColorG,
 ColorB: _col.ColorB,
 MostRecentComment: _mrc.MostRecentComment, 
 DateCreated: _mrc.DateCreated,
 CommentWho: _mrc.CommentWho,
 CommentCount: _mrc.CommentCount
 
 }
 ))
 )
 )
 )
);

 
Thoughts...

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc 

    What are the following items in your formula? 

    - RFPLookUp

    - dictHotelBrands

    - dictHotelChains

    - dictStates

    - dictCountries

    - dictContinents

    - ColMetrosUsed (assuming a collection here)

     

  • sasrsc Profile Picture
    678 on at

    all are SP Lists except the ColMetrosUsed which is a collection. Not sure it matters but the ColMetrosUsed is a subset of another collection that is 3600 rows which are initially imported from a SP List on the App.onStart by the time the user clicks to the screen in the code above the ColMetrosUsed  is already calculated and roughly 40 rows. I don't think that is the issue but worth mentioning.

  • sasrsc Profile Picture
    678 on at

    Our company is hesitant to let us use Azure SQL and definitely won't let us use an on-prem gateway to connect to our on-prem sql databases, so I'm left with exporting my on-prem data into SP lists (which I do via code so it's reasonably efficient using the Graph API and refreshed daily.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc 

    Either datasource will produce the same speed in this case.  SQL will not make it faster.

     

    But, if those are all datasources, then this is the primary source of your slowness.  You are doing multiple data operations (LookUp's) over and over, this will always impact performance.

     

    So, I would suggest the following to at least see if it starts to cut into the performance problem.

    With({_c: 
     ForAll(
     GroupBy(RFPComments, "HotelId", "GroupedItems"),
     With({_top: First(Sort(GroupedItems, Modified, Descending))},
     {
     HotelId: HotelId,
     MostRecentComment: _top.Modified,
     MostRecentCommentStatus: _top.Comment,
     DateCreated: _top.Modified,
     CommentWho: _top.'Modified By'.DisplayName,
     StatusId: _top.StatusId,
     CommentCount: CountRows(GroupedItems)
     }
     )
     ),
     _RFPLookUp: RFPLookUp,
     _dictHotelBrands: dictHotelBrands,
     _dictHotelChains: dictHotelChains,
     _dictStates: dictStates,
     _dictCountries: dictCountries,
     _dictContinents: dictContinents
     
     },
     
     ClearCollect(RFPListing,
     ForAll(HotelRFP As _p,
     With({_mrc: LookUp(_c, HotelId = _p.ID)},
     With({_col: LookUp(_RFPLookUp, ID =_mrc.StatusId),
     _br: LookUp(_dictHotelBrands,ID=_p.brandId),
     _ch: LookUp(_dictHotelChains,ID=_p.chainId)
     },
     Patch(_p,
     {
     Status: _col.Title,
     StateName: LookUp(_dictStates,ID=_p.stateId,stateName),
     CountryCode: LookUp(_dictCountries,ID=_p.countryId,countryCode),
     ContinentCode: LookUp(_dictContinents,ID=_p.continentId,continentCode),
     ChainCode: _ch.Title,
     BrandCode: _br.Title,
     ChainName: _ch.name,
     BrandName: _br.name,
     MetroCode: LookUp(ColMetrosUsed,ID=_p.metroId,metroCode),
     ColorR: _col.ColorR,
     ColorG: _col.ColorG,
     ColorB: _col.ColorB,
     MostRecentComment: _mrc.MostRecentComment, 
     DateCreated: _mrc.DateCreated,
     CommentWho: _mrc.CommentWho,
     CommentCount: _mrc.CommentCount
     
     }
     )
     )
     )
     )
    );

    The goal of the above is to pull your data into memory for the duration of your formula.  LookUp's will then be done against memory instead of individual data operations.

     

    It is still "heavy" because it is pulling in all the data needed.  But, if that seems to cut down on the performance issue, then the next step would be to apply filters to the datasources to reduce the number of records brought in.

  • sasrsc Profile Picture
    678 on at

    That makes sense. I'll do this and update the ticket so others can see if there's an impact by doing this. I get what you are saying.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc 

    Sounds good!

     

    A lot of times if you can filter down data for the app in order to reduce some overhead and performance slowness.  Other times you can filter that down as far as you can go and it still is a lot of data.  When you get to that point, you have to play the "shell" game.  Meaning, the performance hit has to occur somewhere - if you can take a hit here and there through the app, then to the user, it doesn't seem to take as long in just one place.

     

    It's that old "loading" screen trick where you put up some screen and do some interactions even with it, meanwhile loading or processing data in the background.  To the user, they don't really know that the performance hit is happening, they think they are interacting and starting up the app.

  • sasrsc Profile Picture
    678 on at

    That got it down as is to a matter of seconds... which in my mind is perfectly acceptable. Thank you so much for that idea.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard