Add benchmarks for var operation interpolation

Merged
MA
1mo ago
+591-1

Type of change

  • New feature (non-breaking change which adds functionality)

Description

Adds comprehensive benchmarks for the var operation interpolation path, which is used whenever a derived Var is built (arithmetic, comparisons, string/array/object methods, rx.cond, etc.).

The benchmarks isolate the operand interpolation cost, which scales with the amount of VarData carried by operands:

  • Bare vars with no VarData (cheapest)
  • State vars carrying state name and field name
  • Component vars carrying imports and hooks (most expensive)

The suite includes:

  • test_arithmetic_operations and test_comparison_operations: single operand parametrized by VarData content
  • test_chained_operations: operands that are previous results, parametrized by depth (each level re-interpolates a freshly built expression)
  • test_string_operations, test_array_operations, test_object_operations, test_cond_operations: per-type operations over state vars
  • test_format_var_outside_operation: control benchmark for interpolating vars in user code (different path, should not move with operation changes)
  • test_evaluate_var_heavy_page: end-to-end benchmark of a dashboard-shaped page built from derived vars

These benchmarks are designed to catch performance regressions in the operand interpolation path, which the existing page benchmarks barely register since they're dominated by component construction time.

Testing

  • Added comprehensive benchmarks in tests/benchmarks/test_var_operations.py
  • Updated tests/benchmarks/README.md with documentation on running and interpreting the benchmarks
  • Benchmarks can be run with: uv run pytest tests/benchmarks/test_var_operations.py --codspeed

https://claude.ai/code/session_011iWSDifWdaPBHA3aT53Q7Z