Table of Contents

0005. Cache compiled rules per workflow and input shape

Status

Accepted. Recorded retroactively.

Context and problem statement

Compiling a rule is expensive. The compiled delegate depends on the types of the inputs, because the expression is bound to typed parameters, and workflows can be replaced while the engine is running.

Decision drivers

  • Compile each rule only once per input shape.
  • Pick up a changed workflow without restarting.
  • Do not return a compiled rule for the wrong input types.

Considered options

  • Cache per workflow name and the names and full type names of all inputs, and invalidate by comparing timestamps.
  • Cache per workflow name only.
  • Recompile on every call.

Decision outcome

The compiled rules of a workflow are cached under a key made of the workflow name and every input's name and full type name, with inputs sorted by name. Each cache entry and each stored workflow carries a timestamp, and compiled rules older than the workflow are recompiled. Removing a workflow evicts the entries that were compiled from it, matched by the stored workflow name. See Caching and invalidation.

Consequences

  • Good: repeated calls with the same input shapes skip compilation, and replacing a workflow takes effect on the next call.
  • Good: inputs with the same short type name but different types (for example List<int> and List<string>) no longer collide, because the key uses full type names.
  • Bad: every new input shape compiles the workflow again, so unstable dynamic inputs cost performance.
  • Bad: the caches are bounded by entry count, not by size, and entries do not expire by time.
  • Neutral: caches belong to one engine instance, so applications should reuse a single instance.