cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
zmorek
Super User
Super User

Collection vs. Data Source, Efficiency?

In regards to using SharePoint as a data source, when is it more efficient to reference the data source directly vs. using a collection?

 

I have a bunch of lists that are relatively static (little to no changes are made to the lists, and when there are changes, they're minor patches), and they're bound to galleries with various input controls. Each list has under 200 rows (usually under 100 rows).

 

Does it provide a more-responsive experience to users if you first collect the list and use the collection? Or is there a general "threshold" at which it becomes better to use a collection vs. the data source directly?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@zmorek 

It's a balance!!  First, you don't need collections for anything unless you need the ability to add, remove, or update records in an in-memory table.  If you have relatively static tables, then you can simply Set(aVariable, yourDataSourceOrFilter)

A table is a table!!  A variable can be a table just as a collection is a table.  A variable has less overhead than a collection and is all you need.

 

So, for non-changing datasources, set a variable and you'll have less "chat" with the session table. 

For changing datasource (records you'll be interacting with in the app), a collection usually will slow down your app.

Why?  Because, you first will be loading ALL the records into it - this will take a performance hit.  Then, no doubt, at some point, you will recollect the same records because you want your collection to be "up-to-date" - this will hit your performance again.  

PowerApps has built in to it, features that allow your data to be retrieved on demand.  So, for example, with a datasource directly, when your app starts, it creates a session table in the cloud with a "stub" of a table.  When you "demand" a record, PowerApps will get it from the real datasource and put into the session table and transmit to your app.  Note: it used to be that after than, any time you referenced that record, it was sent to you as it is in the session table.  For SharePoint at least, it now goes once again to the datasource and reloads that record.

SO, at startup, using a DataSource means that the performance hit was just to initialize the "stub" in the session.  Using a collection means that every record has to be gathered and put in the session stub and then to your app datasource.

Plus, once loaded, to really manage a collection without the performance hits takes a considerable amount of work to avoid having to do a recollect on the collection again, thus suffering the same performance hit.

 

Hopefully that is clear and helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

7 REPLIES 7
RandyHayes
Super User
Super User

@zmorek 

It's a balance!!  First, you don't need collections for anything unless you need the ability to add, remove, or update records in an in-memory table.  If you have relatively static tables, then you can simply Set(aVariable, yourDataSourceOrFilter)

A table is a table!!  A variable can be a table just as a collection is a table.  A variable has less overhead than a collection and is all you need.

 

So, for non-changing datasources, set a variable and you'll have less "chat" with the session table. 

For changing datasource (records you'll be interacting with in the app), a collection usually will slow down your app.

Why?  Because, you first will be loading ALL the records into it - this will take a performance hit.  Then, no doubt, at some point, you will recollect the same records because you want your collection to be "up-to-date" - this will hit your performance again.  

PowerApps has built in to it, features that allow your data to be retrieved on demand.  So, for example, with a datasource directly, when your app starts, it creates a session table in the cloud with a "stub" of a table.  When you "demand" a record, PowerApps will get it from the real datasource and put into the session table and transmit to your app.  Note: it used to be that after than, any time you referenced that record, it was sent to you as it is in the session table.  For SharePoint at least, it now goes once again to the datasource and reloads that record.

SO, at startup, using a DataSource means that the performance hit was just to initialize the "stub" in the session.  Using a collection means that every record has to be gathered and put in the session stub and then to your app datasource.

Plus, once loaded, to really manage a collection without the performance hits takes a considerable amount of work to avoid having to do a recollect on the collection again, thus suffering the same performance hit.

 

Hopefully that is clear and helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

zmorek
Super User
Super User

This is an amazingly insightful answer, thank you for taking the time to do that!

RandyHayes
Super User
Super User

@zmorek 

Happy to share!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
timl
Super User
Super User

Just to repeat what @zmorek said, that's an excellent summary Randy!

For anyone else reading this, the other comment I would make about storing tables/filter results in variables rather than collections is that the 'variables' section of the designer shows all the places in the app where you use the table variable, which can make it easier to maintain an app (the collections section of the designer shows only a preview of the data, and not where you set/use the collection).

RandyHayes
Super User
Super User

Good point @timl 

I'm so used to having formulas in a common place that I forget about the variable viewer!  I always wished they would have put the locations of formulas in the collection viewer.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
timl
Super User
Super User

I agree @RandyHayes - they should show the locations of the formulas in the collection viewer. I'll create a post in the ideas forum when I get a moment, and maybe we might see this feature added in the near future!

RandyHayes
Super User
Super User

@timl 

Yes, there is one (actually a few) there already. Since 2018 and "under review".

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,071)