Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
48c5706
test: add benchmarks and a runner that show the scaling, not just the…
toxik Aug 6, 2026
454b249
perf(feel-evaluator): move partial results instead of copying them
toxik Aug 4, 2026
3683a0c
perf(feel-parser): append list items instead of prepending them
toxik Aug 4, 2026
b74a6fb
perf(feel-evaluator): read the path base entry without cloning the co…
toxik Aug 4, 2026
78c51bf
perf(feel): box the FunctionDefinition payload
toxik Aug 4, 2026
47ee4e3
perf(feel-regex): cache compiled patterns
toxik Aug 4, 2026
7e1d018
perf(feel): share context entries behind an Arc
toxik Aug 4, 2026
fb3dec0
perf(feel-evaluator): evaluate independent for bodies in parallel
toxik Aug 4, 2026
7139da6
perf(dsntk): use mimalloc as the global allocator
toxik Aug 4, 2026
084e3f2
perf(feel-evaluator): free the input text and its syntax tree once th…
toxik Aug 4, 2026
e382db0
perf(feel): intern FEEL names to an integer handle
toxik Aug 4, 2026
e8af2ab
perf(feel-evaluator): read a data literal into a value without a clos…
toxik Aug 5, 2026
6b9bc1f
perf(feel): take `size_of::<Value>()` from 64 bytes to 48
toxik Aug 5, 2026
82fbcbd
fix(feel): stop leaving interned names unranked, which made them comp…
toxik Aug 5, 2026
c440b4e
perf(feel): build a one-entry context without Arc::make_mut
toxik Aug 5, 2026
a8996fe
perf(feel): share a date and time payload instead of copying it
toxik Aug 5, 2026
386fc42
perf(feel-evaluator): intern three constant names once, not per evalu…
toxik Aug 5, 2026
10899c4
fix(feel-parser): stop absorbing a following keyword into an unresolv…
toxik Aug 5, 2026
59b02a2
perf(feel-evaluator): evaluate a repeated call in a filter predicate …
toxik Aug 5, 2026
90e73d2
fix(feel-evaluator): stop a hoisted subexpression leaking into a cons…
toxik Aug 5, 2026
2c49cf1
perf(feel-evaluator): answer a filter that is really an index without…
toxik Aug 5, 2026
55ae70a
fix(feel-parser): stop absorbing the `in` comparison operator into a …
toxik Aug 5, 2026
88c7778
fix(feel-evaluator): stop two builtins from mishandling a null list e…
toxik Aug 5, 2026
cfc0896
fix(feel-evaluator): close two holes in the parallel `for` safety gate
toxik Aug 6, 2026
788fbc3
fix(feel): stop the name table filling, and stop lookups feeding it
toxik Aug 6, 2026
7f39b69
fix(model-evaluator): evaluate `?` in a unary test instead of reading…
toxik Aug 6, 2026
699d170
perf(feel-regex): give each thread its own compiled pattern cache
toxik Aug 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dsntk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tck = ["dsntk-server/tck"]

[dependencies]
actix-web = { workspace = true }
mimalloc = "0.1"
antex = { workspace = true }
base64 = { workspace = true }
clap = { workspace = true }
Expand Down
60 changes: 38 additions & 22 deletions dsntk/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,28 +1010,44 @@ fn parse_dmn_model(dmn_file_name: &str, cm: ColorMode) {

/// Evaluates DMN model loaded from XML file.
fn evaluate_dmn_model(input_file_name: &str, dmn_file_name: &str, invocable_name: &str) {
match fs::read_to_string(dmn_file_name) {
Ok(dmn_file_content) => match fs::read_to_string(input_file_name) {
Ok(input_file_content) => match dsntk_evaluator::evaluate_context(&FeelScope::default(), &input_file_content) {
Ok(input_data) => match dsntk_model::parse(&dmn_file_content) {
Ok(definitions) => {
let model_namespace = definitions.namespace().to_string();
let model_name = definitions.name().to_string();
match dsntk_evaluator::ModelEvaluator::new(&[definitions]) {
Ok(model_evaluator) => {
let result = model_evaluator.evaluate_invocable(&model_namespace, &model_name, invocable_name, &input_data);
println!("{}", result.jsonify())
}
Err(reason) => eprintln!("building model evaluator failed with reason: {reason}"),
}
}
Err(reason) => eprintln!("parsing model failed with reason: {reason}"),
},
Err(reason) => eprintln!("evaluating input data failed with reason: {reason}"),
},
Err(reason) => eprintln!("loading input data file `{input_file_name}` failed with reason: {reason}"),
},
Err(reason) => eprintln!("loading model file `{dmn_file_name}` failed with reason: {reason}"),
let dmn_file_content = match fs::read_to_string(dmn_file_name) {
Ok(dmn_file_content) => dmn_file_content,
Err(reason) => {
eprintln!("loading model file `{dmn_file_name}` failed with reason: {reason}");
return;
}
};
let input_file_content = match fs::read_to_string(input_file_name) {
Ok(input_file_content) => input_file_content,
Err(reason) => {
eprintln!("loading input data file `{input_file_name}` failed with reason: {reason}");
return;
}
};
let input_data = match dsntk_evaluator::evaluate_context(&FeelScope::default(), &input_file_content) {
Ok(input_data) => input_data,
Err(reason) => {
eprintln!("evaluating input data failed with reason: {reason}");
return;
}
};
// The input data is now a context, so the text is dead. For a large input,
// this text is tens or hundreds of megabytes. Free it here instead of holding
// it until the process exits.
drop(input_file_content);
match dsntk_model::parse(&dmn_file_content) {
Ok(definitions) => {
let model_namespace = definitions.namespace().to_string();
let model_name = definitions.name().to_string();
match dsntk_evaluator::ModelEvaluator::new(&[definitions]) {
Ok(model_evaluator) => {
let result = model_evaluator.evaluate_invocable(&model_namespace, &model_name, invocable_name, &input_data);
println!("{}", result.jsonify())
}
Err(reason) => eprintln!("building model evaluator failed with reason: {reason}"),
}
}
Err(reason) => eprintln!("parsing model failed with reason: {reason}"),
}
}

Expand Down
9 changes: 9 additions & 0 deletions dsntk/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/// Use mimalloc instead of the system allocator.
///
/// Evaluation spends about half its time in `malloc` and `free`, and macOS
/// `libmalloc` never returns freed small blocks to the operating system. So peak
/// resident memory holds every page the parse phase touched, long after the parse
/// data dies. mimalloc purges free pages, so the peak tracks live data instead.
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

/// ÐecisionToolkit entrypoint.
#[actix_web::main]
async fn main() -> std::io::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions feel-evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
rayon = "1"
regex = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
Expand Down
64 changes: 64 additions & 0 deletions feel-evaluator/benches/list_scaling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! Evaluating a `for` expression, at three sizes.
//!
//! As in the parser benchmark of the same shape, read the **ratio between the sizes** rather
//! than any single time. Each size runs four times the iterations of the one before it, so a
//! linear evaluator answers in about four times the time.
//!
//! `for` binds the implicit variable `partial` to the results of all previous iterations. An
//! evaluator that copies that list on every iteration pays for every result collected so far,
//! which makes the whole expression quadratic in the number of iterations. It does so whether
//! or not the body ever reads `partial`, and neither of these bodies reads it.

#![feature(test)]

extern crate test;

use dsntk_feel::values::Value;
use dsntk_feel::{FeelScope, scope, value_number};
use dsntk_feel_evaluator::prepare;
use test::Bencher;

/// Returns an expression that runs `count` iterations and counts the results.
fn counted_for(count: usize) -> String {
format!("count(for item in 1..{count} return item + 1)")
}

#[bench]
fn feel_evaluator_list_scaling_0001(b: &mut Bencher) {
let scope = scope!();
let input = counted_for(100);
let node = dsntk_feel_parser::parse_expression(&scope, &input, false).unwrap();
let evaluator = prepare(&node);
assert_eq!(value_number!(100), evaluator(&scope));
b.iter(|| evaluator(&scope));
}

#[bench]
fn feel_evaluator_list_scaling_0002(b: &mut Bencher) {
let scope = scope!();
let input = counted_for(400);
let node = dsntk_feel_parser::parse_expression(&scope, &input, false).unwrap();
let evaluator = prepare(&node);
assert_eq!(value_number!(400), evaluator(&scope));
b.iter(|| evaluator(&scope));
}

#[bench]
fn feel_evaluator_list_scaling_0003(b: &mut Bencher) {
let scope = scope!();
let input = counted_for(1600);
let node = dsntk_feel_parser::parse_expression(&scope, &input, false).unwrap();
let evaluator = prepare(&node);
assert_eq!(value_number!(1600), evaluator(&scope));
b.iter(|| evaluator(&scope));
}

#[bench]
fn feel_evaluator_list_scaling_0004(b: &mut Bencher) {
let scope = scope!();
let input = counted_for(6400);
let node = dsntk_feel_parser::parse_expression(&scope, &input, false).unwrap();
let evaluator = prepare(&node);
assert_eq!(value_number!(6400), evaluator(&scope));
b.iter(|| evaluator(&scope));
}
66 changes: 66 additions & 0 deletions feel-evaluator/examples/scaling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! Runs one of the scaling shapes once, at any size, and reports the time.
//!
//! The benchmarks next door stop at a few thousand items, because a cost that grows with the
//! square of the input makes larger sizes take minutes per iteration and `cargo bench` runs
//! many iterations. This runs the same shapes exactly once, so the large sizes stay usable.
//!
//! ```text
//! cargo run --release --example scaling -- for 200000
//! cargo run --release --example scaling -- list 200000
//! ```
//!
//! For peak memory, wrap it in the system timer rather than adding a dependency:
//!
//! ```text
//! /usr/bin/time -l cargo run --release --example scaling -- for 200000 # macOS
//! /usr/bin/time -v cargo run --release --example scaling -- for 200000 # Linux
//! ```
//!
//! `for` evaluates `count(for item in 1..N return item + 1)`, which runs N iterations. `list`
//! parses a literal holding N numbers. Compare the same command across two revisions, and
//! compare each revision against itself at two sizes: four times the items should cost about
//! four times the time.

use dsntk_feel::values::Value;
use dsntk_feel::{FeelScope, scope};
use dsntk_feel_evaluator::prepare;
use std::time::Instant;

fn main() {
let args: Vec<String> = std::env::args().collect();
let shape = args.get(1).cloned().unwrap_or_else(|| "for".to_string());
let count: usize = args.get(2).and_then(|a| a.parse().ok()).unwrap_or(200_000);
let scope = scope!();
match shape.as_str() {
"for" => {
let input = format!("count(for item in 1..{count} return item + 1)");
let started = Instant::now();
let node = dsntk_feel_parser::parse_expression(&scope, &input, false).expect("parsing failed");
let evaluator = prepare(&node);
let result = evaluator(&scope);
let elapsed = started.elapsed();
assert_eq!(Value::Number(count.into()), result, "the loop did not run {count} times");
println!("for items {count:>9} {:>10.3} s", elapsed.as_secs_f64());
}
"list" => {
let mut input = String::with_capacity(count * 8 + 2);
input.push('[');
for index in 0..count {
if index > 0 {
input.push(',');
}
input.push_str(&index.to_string());
}
input.push(']');
let started = Instant::now();
let node = dsntk_feel_parser::parse_expression(&scope, &input, false).expect("parsing failed");
let elapsed = started.elapsed();
assert!(matches!(node, dsntk_feel_parser::AstNode::List(_)), "expected a list");
println!("list items {count:>9} {:>10.3} s", elapsed.as_secs_f64());
}
other => {
eprintln!("unknown shape `{other}`, expected `for` or `list`");
std::process::exit(1);
}
}
}
48 changes: 32 additions & 16 deletions feel-evaluator/src/bifs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ pub fn context_merge(contexts: &Value) -> Value {
for item in items {
match item {
Value::Context(ctx) => result_ctx.zip(ctx),
Value::Null(_) => {}
// A null entry is out of domain, just like any other non-context value. It is
// also the entry a failed expression produces, so it is the entry that most
// needs this diagnostic.
other => return invalid_argument_type!("context merge", "context", other.type_of()),
}
}
Expand Down Expand Up @@ -624,10 +626,10 @@ pub fn date_3(year_value: &Value, month_value: &Value, day_value: &Value) -> Val
pub fn date_and_time_1(value: &Value) -> Value {
if let Value::String(text) = value {
if let Ok(date_time) = FeelDateTime::try_from(text.as_str()) {
return Value::DateTime(date_time);
return Value::DateTime(date_time.into());
}
if let Ok(date) = FeelDate::from_str(text) {
return Value::DateTime(FeelDateTime::new(date, FeelTime::local(0, 0, 0, 0)));
return Value::DateTime(FeelDateTime::new(date, FeelTime::local(0, 0, 0, 0)).into());
}
value_null!("[core::date and time] invalid date or date and time '{}'", text)
} else {
Expand All @@ -640,13 +642,13 @@ pub fn date_and_time_2(date_value: &Value, time_value: &Value) -> Value {
match date_value {
Value::DateTime(date_time) => {
if let Value::Time(time) = time_value {
return Value::DateTime(FeelDateTime::new(date_time.date(), time.clone()));
return Value::DateTime(FeelDateTime::new(date_time.date(), time.clone()).into());
}
invalid_argument_type!("date and time", "time", time_value.type_of())
}
Value::Date(date) => {
if let Value::Time(time) = time_value {
return Value::DateTime(FeelDateTime::new(date.clone(), time.clone()));
return Value::DateTime(FeelDateTime::new(date.clone(), time.clone()).into());
}
invalid_argument_type!("date and time", "time", time_value.type_of())
}
Expand Down Expand Up @@ -1074,11 +1076,16 @@ pub fn get_entries(context: &Value) -> Value {
pub fn get_value(context: &Value, key: &Value) -> Value {
if let Value::Context(ctx) = context {
if let Value::String(entry_key) = key {
let name = Name::from(entry_key.to_owned());
if let Some(entry_value) = ctx.get_entry(&name) {
entry_value.clone()
} else {
value_null!()
// Look the key up without interning it. Interning on every probe, including the ones
// that miss, grows the table without bound, because the interner never releases a
// name. A key that was never interned cannot name an entry in any context, so the
// miss answers null either way.
match Name::existing(entry_key) {
Some(name) => match ctx.get_entry(&name) {
Some(entry_value) => entry_value.clone(),
None => value_null!(),
},
None => value_null!(),
}
} else {
invalid_argument_type!("get value", "string", key.type_of())
Expand Down Expand Up @@ -1284,7 +1291,8 @@ pub fn list_replace(list: &Value, position_or_match: &Value, new_item: &Value) -
value_null!("position exceeds integer range")
}
}
Value::FunctionDefinition(parameters, body, false, _, closure_ctx, _) => {
Value::FunctionDefinition(fd) if !fd.2 => {
let (parameters, body, _, _, closure_ctx, _) = &**fd;
if parameters.len() != 2 {
return value_null!("list replace: matching function must have exactly two arguments");
}
Expand Down Expand Up @@ -1680,7 +1688,7 @@ pub fn not(negand: &Value) -> Value {

/// Returns current date and time.
pub fn now() -> Value {
Value::DateTime(FeelDateTime::now())
Value::DateTime(FeelDateTime::now().into())
}

/// Converts string to a number.
Expand Down Expand Up @@ -2132,7 +2140,10 @@ pub fn round_up(n: &Value, scale: &Value) -> Value {

pub fn sort(list: &Value, ordering_function: &Value) -> Value {
if let Value::List(items) = list {
if let Value::FunctionDefinition(parameters, body, false, _, closure_ctx, _) = ordering_function {
if let Value::FunctionDefinition(fd) = ordering_function
&& !fd.2
{
let (parameters, body, _, _, closure_ctx, _) = &**fd;
if parameters.len() == 2 {
let mut elements = items.clone();
elements.sort_by(|x, y| {
Expand Down Expand Up @@ -2434,7 +2445,7 @@ pub fn string(value: &Value) -> Value {
}
}

/// Returns the number of characters in string.
/// Joins a list of strings, ignoring null elements, and separates them with a delimiter.
pub fn string_join(list: &Value, delimiter: &Value) -> Value {
match list {
Value::List(items) => {
Expand All @@ -2444,13 +2455,18 @@ pub fn string_join(list: &Value, delimiter: &Value) -> Value {
_ => return value_null!("string join: invalid delimiter, expected string, actual value type is {}", delimiter.type_of()),
};
let mut joined_string = String::new();
for (i, item) in items.iter().enumerate() {
// The delimiter goes before every string except the first one that is
// actually kept. Counting from the list index instead puts a delimiter at
// the front when the list starts with a null.
let mut joined_any = false;
for item in items.iter() {
match item {
Value::String(s) => {
if i > 0 {
if joined_any {
joined_string.push_str(&delimiter);
}
joined_string.push_str(s);
joined_any = true;
}
Value::Null(_) => {}
other => return invalid_argument_type!("string join", "string", other.type_of()),
Expand Down
Loading