Best practices for Arcade expressions

Some applications of ArcGIS Arcade are better suited than others for specific use cases. The following are some of the recommended best practices for using Arcade expressions in ArcGIS Velocity analytic tools:

  • Expression complexity—While Arcade allows you to write complex scripts, declare variables, and define and call functions, when building Arcade scripts in Velocity it is recommended that you keep them as simple as possible. Complex scripts tend to have more potential for errors, but more importantly, they also have more impact on analytic performance. Shorter scripts and expressions are interpreted more quickly and have a lower impact on processing speed.
  • Expression length—Arcade supports lengthy multiline scripts, but just as with complex scripts, long scripts may also adversely impact processing speed. It is recommended that you keep scripts as short as possible to avoid unnecessary decreases in performance.
  • Avoid loops—When writing scripts and programs, it can be useful to leverage looping routines that iterate a set of data and repeat a procedure or test for specific conditions. Although this is supported in Velocity, it can reduce performance of analytics, sometimes severely. Use looping logic infrequently and judiciously in analytic expressions.

    Avoid conditions in your expressions that may lead to infinite looping when the analytic is running. If this occurs, you may observe a significant impact to the analytic's performance.

    When Velocity validates an analytic and determines that it may contain looping logic, a validation warning is returned. This does not prevent you from running the analytic, but it serves as a reminder that loops can have a negative impact on performance.

  • Testing an expression with sample values—Testing with sample values may be necessary to produce the correct data type from the configured inputs.

    For example, if you have a string field named ingestion_time containing time values such as 2022-11-30T16:05:18Z, and you want to parse the strings into times, you can use an expression such as Date($feature.ingestion_time). The Arcade expression builder attempts to validate the expression using a sample string. The default sample string is Pacific, which does not successfully parse to a time. Once the expression builder is closed, a validation error is returned indicating that you must configure a valid expression that returns data in the target field type.

    Editor testing expression with default value

    You can update this behavior by passing in your own valid sample string in the expression builder. To do so, open the expression builder, and from the Profile variables pane, click $feature to access the variables, and then choose the string field containing the time information.

    Editing the sample value

    Type an example string in the same time format as the values in the field. When you run the expression, a valid time value will be generated, and the expression can be used in the tool successfully.

    Testing an expression with a sample time value