0004. Evaluate global parameters once per execution
Status
Accepted. Recorded retroactively. Introduced in version 6.0.1 (issue 714).
Context and problem statement
GlobalParams are named expressions that every rule of a workflow can use. They were evaluated once for every rule, so a global that did expensive work (for example a lookup) ran as many times as there were rules, although its value cannot change within one execution.
Decision drivers
- Do the work of a global parameter once per call.
- Keep the values visible to every rule and in the result's
Inputs. - Keep per-rule
LocalParamsindependent of each other.
Considered options
- Compile all global parameters into one delegate at registration, evaluate it once per execution and pass the values to each rule as extra inputs.
- Keep evaluating per rule and let authors cache.
- Memoize inside the expression parser.
Decision outcome
When a workflow is compiled, its GlobalParams are compiled into a single delegate. ExecuteAllRulesAsync evaluates it once and appends the results as extra RuleParameters for every rule. Local parameters are still evaluated per rule. See the evaluation pipeline.
Consequences
- Good: the cost of a global parameter no longer grows with the number of rules.
- Good: values are consistent across all rules of one call.
- Bad: a failure in a global parameter is reported on every rule of the workflow.
- Bad: a caller input must not share a name with a global parameter, and the
EvaluateRuleaction must drop forwarded values that the target workflow recomputes. - Neutral: the delegate is cached next to the compiled rules, and is replaced or removed together with them.