Back to KB
Difficulty
Intermediate
Read Time
6 min

Scoped Re-evaluation: Preventing Unnecessary FEEL Expression Evaluation in Large Forms

By Codcompass TeamΒ·Β·6 min read

Current Situation Analysis

The default evaluator pattern in Form-JS operates on a broadcast-and-re-evaluate assumption: whenever the changed event fires, all evaluators re-scan and re-evaluate every component. While acceptable for small forms, this approach creates a severe performance bottleneck at scale, particularly during pre-population or dynamic data loading.

Failure Mode Analysis:

  • Event Storm Multiplication: When a 50-field form loads with pre-populated data, Form-JS writes each field's value sequentially. Each write triggers a changed event, resulting in 50 discrete events.
  • O(NΓ—M) Evaluation Explosion: With 5 evaluators running evaluateAll() on every event, the system performs 50 events Γ— 5 evaluators Γ— 50 components = 12,500 FEEL evaluations during a single load cycle.
  • Redundant AST Parsing: The feelin library parses expressions, builds Abstract Syntax Trees (ASTs), and resolves contexts on every run. Even simple expressions incur 1-5ms overhead. At scale, this accumulates to 200-500ms of synchronous JavaScript execution, blocking the UI thread and causing perceptible lag.
  • Irrelevant Scope Triggering: Evaluators like DateTimeValidationEvaluator only care about date, datetime, and time fields. Yet, they fire identically when text inputs, dropdowns, or checkboxes change, wasting cycles on irrelevant data mutations.

Traditional "re-evaluate everything" patterns fail because they treat all state changes as globally significant, ignoring domain-specific boundaries and context relevance.

WOW Moment: Key Findings

ApproachEvaluation Runs (50-field load)FEEL OperationsExecution Time (ms)Context Size
Unscoped Baseline502,650~45050+ keys
Field-Type Gating Only3159~4550+ keys
Full Scoped Optimization315~83-5 keys

Key Findings:

  • Event Filtering Yields 83% Reduction: Simply checking whether the changed field matches the evaluator's target type drops evaluation runs from 50 to 3 during pre-population.
  • Registry Lookup Eliminates O(n) Scans: Pre-building a Set of relevant field keys reduces type-checking from linear array scans to O(1) hash lookups.
  • Context Pruning Cuts FEEL Overhead: Filtering the evaluation context to only relevant keys reduces variable resolution overhead and prevents accidental key collisions (e.g., a text field named startDate polluting datetime comparisons).
  • Sweet Spot: The combination

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back