While trying to optimize a data expression for Dashboard with @ChrisSpadi , I realized that the first time you access a feature of a featureset, it takes a very long time. A quick example:
var times_load = []
var times_read_first = []
var times_read_all = []
var start
for(var i = 0; i < 10; i++) {
// load the layer
start = Now()
var fs = FeaturesetByPortalItem(Portal("https://arcgis.com"), "78ea2a77985743abb7e83b021da2f728", 0, ["OBJECTID"], false)
Push(times_load, DateDiff(Now(), start))
// access the first feature
start = Now()
var oid = First(fs).OBJECTID
Push(times_read_first, DateDiff(Now(), start))
// acccess all features
start = Now()
for(var f in fs) {
var oid = f.OBJECTID
}
Push(times_read_all, DateDiff(Now(), start))
}
Console(`Loading the layer: ${Round(Average(times_load), 0)} milliseconds. ${times_load}`)
Console(`Reading the first element: ${Round(Average(times_read_first), 0)} milliseconds. ${times_read_first}`)
Console(`Reading all elements: ${Round(Average(times_read_all), 0)} milliseconds. ${times_read_all}`)
Loading the layer: 274 milliseconds. [485,255,254,250,246,254,247,247,247,253]
Reading the first element: 588 milliseconds. [1202,479,678,446,546,350,1126,349,340,361]
Reading all elements: 0 milliseconds. [1,0,0,0,0,0,0,0,0,0]
This layer has only 8 features. As you can see, getting the layer reference with FeaturesetByPortalItem takes ~0.25 seconds. Accessing the first feature takes ~0.6 seconds (with widely varying times). After that first time, accessing features is instantaneous.
Until now, I assumed that FeaturesetBy* loads the layer into the RAM. But this makes it seems as if FeaturesetBy* only establishes a connection to the layer and the first data access reads the whole layer into RAM.
Is this interpretation correct? Is there anything we can do to optimize these times (besides specifying fields and not loading geometries, both of which I did here)?
@jcarlson , @XanderBakker