Arcade expressions - does tighter code give better performance on AGOL?

1420
4
Jump to solution
12-07-2020 10:39 AM
AmyRoust
Occasional Contributor III

Has anyone tested Arcade's performance with tight vs more verbose expressions? For example, here is an expression I wrote to count the number of accidents that occurred within 150 feet of a road centerline:

 

 

Count(Intersects((FeatureSetByName($map, "Accident"), Buffer($feature, 150, "feet")))

 

 

A more verbose way to get the same result might be:

 

 

var accidents = FeatureSetByName($map, "Accident")
var roadBuffer = Buffer($feature, 150, 'feet')
var roadAccidentIntersects = Intersects(accidents, roadBuffer)
var countAccidents = Count(roadAccidentIntersects)
return countAccidents

 

 

 

Does anyone know if one expression would perform better than the other in an AGOL pop-up? I've definitely noticed that the more you click on features in a map with spatial analysis, the faster the browser gets at calculating the results. I'm just wondering if there is an advantage to writing tight code as opposed to more readable code.

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @AmyRoust ,

 

Some time ago I read that it is more performant to have multiple functions on the same line since this would reduce the number of requests to the server. This is something Paul Barker mentioned in his blog: https://www.esri.com/arcgis-blog/products/mapping/mapping/whats-new-with-arcade-taking-a-stroll-thro... 

 

On the other hand, I have never been able to confirm this. 

 

CC: @HusseinNasser2 

View solution in original post

0 Kudos
AmyRoust
Occasional Contributor III

The answer is embedded in that article that you referenced. Specifically, "Because of that lazy execution and chaining, the following two expressions are identical, and will have the same performance with respect to query execution:" The two expressions that follow are nearly identical to what I posted. Thank you - that was an interesting article.

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

Although the example you give will have more code being executed, the only real difference is variable assignment, which is trivial in terms of computing/processing.  Any difference will likely be negligible to non-existent, and what you get in return is code that is harder to read and more difficult to maintain.  Code golf can be fun, but it seldom is a performance optimization.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @AmyRoust ,

 

Some time ago I read that it is more performant to have multiple functions on the same line since this would reduce the number of requests to the server. This is something Paul Barker mentioned in his blog: https://www.esri.com/arcgis-blog/products/mapping/mapping/whats-new-with-arcade-taking-a-stroll-thro... 

 

On the other hand, I have never been able to confirm this. 

 

CC: @HusseinNasser2 

0 Kudos
AmyRoust
Occasional Contributor III

The answer is embedded in that article that you referenced. Specifically, "Because of that lazy execution and chaining, the following two expressions are identical, and will have the same performance with respect to query execution:" The two expressions that follow are nearly identical to what I posted. Thank you - that was an interesting article.

JoshuaBixby
MVP Esteemed Contributor

@AmyRoust, I marked your comment as a solution as well because you specifically call out the part of the blog that states performance won't matter with your code whether it is a single line or multi-line because of the structure of your code.