Add benchmarks for var operation interpolation
Merged
MA
1mo ago+591+591+012345678901234567890123456789-1-1-0123456789
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_operationsandtest_comparison_operations: single operand parametrized byVarDatacontenttest_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 varstest_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.mdwith documentation on running and interpreting the benchmarks - Benchmarks can be run with:
uv run pytest tests/benchmarks/test_var_operations.py --codspeed