Skip to content

Replace custom CEL evaluator with cel-rust#718

Draft
nicolasburtey wants to merge 1 commit intomainfrom
replace-cel-with-cel-rust
Draft

Replace custom CEL evaluator with cel-rust#718
nicolasburtey wants to merge 1 commit intomainfrom
replace-cel-with-cel-rust

Conversation

@nicolasburtey
Copy link
Copy Markdown
Member

@nicolasburtey nicolasburtey commented May 1, 2026

Summary

  • replace the custom CEL evaluator path in cala-cel-interpreter with cel-rust's Program/Context execution
  • add compatibility conversions between Cala CelValue and cel-rust Value, including opaque Decimal and Uuid wrappers
  • re-register Cala-specific CEL functions: date, uuid, decimal, decimal.Add, and timestamp format
  • remove the retired cala-cel-parser crate, generated LALRPOP parser, stale interpreter package modules, and release-script references to the parser crate
  • adjust date default validation for the timestamp-backed date representation

Verification

  • cargo check -p cala-cel-interpreter --features fail-on-warnings
  • SQLX_OFFLINE=true cargo check --workspace
  • SQLX_OFFLINE=true cargo test --workspace --lib

Performance

Compared main (69006ee9) against this branch (34548dbb).

Compile time

Check main CEL replacement Delta
cargo check -p cala-cel-interpreter --features fail-on-warnings 13.30s 12.87s ~3% faster
SQLX_OFFLINE=true cargo check --workspace 50.34s 52.04s ~3.4% slower

Pure CEL microbenchmark

  • context construction: ~4.4x slower (1.32us -> 5.80us)
  • parsing: ~30x-55x slower depending on expression
  • evaluation: mixed for simple expressions, but slower on velocity-style expressions:
    • context.vars.account.metadata.check_velocity: ~49% slower
    • context.vars.entry.units == decimal('100'): ~27% slower
    • closed-as-of velocity condition: ~67% slower

Parse cost may matter less for normal runtime if expressions are parsed once and reused, but context construction and velocity-style evaluation are on the hot path.

DB-backed cala-perf velocity benchmarks

Ran with a temporary local Postgres cluster and reset DB state before each branch:

cargo bench -p cala-perf --bench ledger_benchmarks -- velocity --sample-size 20 --warm-up-time 1 --measurement-time 5
Benchmark main mean CEL replacement mean Delta
post_simple_transaction_with_velocity 1.077 ms 1.313 ms ~22% slower
post_simple_transaction_with_skipped_velocity 1.003 ms 1.103 ms ~10% slower
post_simple_transaction_with_hit_velocity 543 us 636 us ~17% slower

Overall: compile impact is small/mixed, but CEL-heavy runtime paths regress by roughly 10-22% in the DB-backed velocity benchmarks, and isolated CEL parsing/context construction are substantially slower.

Not run

  • OTel/Jaeger runtime tracing. Docker/Podman were unavailable locally, so the runtime comparison used the DB-backed local Postgres benchmark instead.

Note

High Risk
High risk because it replaces the core CEL parsing/execution engine and rewires type/function handling, which can change evaluation semantics and error behavior across templates/params.

Overview
Switches cala-cel-interpreter from the in-repo cala-cel-parser + custom AST evaluator to cel::Program/cel::Context execution, compiling expressions once and executing them against a registered runtime context.

Reimplements Cala builtins on top of cel (e.g. date, uuid, decimal, decimal.Add, timestamp format) and adds bidirectional conversions between Cala CelValue/CelKey and cel::objects::Value using opaque wrappers for Decimal/Uuid.

Removes the retired cala-cel-parser crate (LALRPOP grammar/build scripts and related context “package” plumbing), updates workspace deps/lockfile accordingly (including new cel transitive deps and dual thiserror versions), and adjusts/coarsens some tests and date coercion to align with the new timestamp-backed representation.

Reviewed by Cursor Bugbot for commit 34548db. Bugbot is set up for automated code reviews on this repo. Configure here.

}
values => Err(ExecutionError::invalid_argument_count(2, values.len())),
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decimal arithmetic and ordering operators lost with opaque wrapping

Medium Severity

Wrapping Decimal as Value::Opaque removes support for native +, -, * operators and <, <=, >, >= comparisons that the old evaluator explicitly provided. Only decimal.Add is re-implemented as a named function. There are no equivalents for subtraction or multiplication, and cel-rust cannot apply arithmetic or ordering operators to opaque types. In a financial ledger system, this regression in decimal capabilities is concerning even if current expressions happen to use decimal.Add() rather than the + operator.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d9dd2cd. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

📊 Performance Report

Commit: 34548db
Updated: 2026-05-02 02:09:25 UTC

Cala Performance Benchmark Results (non-representative)

Criterion Benchmark Results (single-threaded)

Benchmark Time per Run Throughput % vs Baseline
post_simple_transaction 8.609ms 116 tx/s 0 (baseline)
post_and_recalculate_ec_account_set 17.443ms 57 tx/s -102.0%
post_and_batch_recalculate_ec_account_set 12.936ms 77 tx/s -50.0%
post_multi_layer_transaction 7.618ms 131 tx/s +11.0%
post_simple_transaction_with_effective_balances 9.329ms 107 tx/s -8.0%
post_simple_transaction_with_skipped_velocity 6.621ms 151 tx/s +23.0%
post_simple_transaction_with_velocity 8.204ms 121 tx/s +4.0%
post_simple_transaction_with_hit_velocity 4.098ms 243 tx/s +52.0%
post_simple_transaction_with_one_account_set 6.904ms 144 tx/s +19.0%
post_simple_transaction_with_five_account_sets 8.164ms 122 tx/s +5.0%
post_simple_transaction_with_ec_account_set 6.585ms 151 tx/s +23.0%

Load Testing Results (parallel-execution)

Scenario tx/s
1 parallel 87.99
2 parallel 122.59
5 parallel 154.84
10 parallel 158.71
20 parallel 155.93
2 contention 118.07
5 contention 134.09
2 acct_sets 113.15
5 acct_sets 122.25

Note: Performance results may vary based on system resources and database state.

Last updated by commit 34548db

@nicolasburtey nicolasburtey force-pushed the replace-cel-with-cel-rust branch from d9dd2cd to 7063f15 Compare May 1, 2026 23:57
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7063f15. Configure here.

Comment thread cala-cel-interpreter/src/value.rs
@nicolasburtey nicolasburtey force-pushed the replace-cel-with-cel-rust branch from 7063f15 to 34548db Compare May 2, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant