perf: general performance improvements

This commit is contained in:
Stefan
2026-08-03 13:20:23 +02:00
parent 32a8f12547
commit f31f952256
64 changed files with 2220 additions and 539 deletions
+6 -7
View File
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::rc::Rc;
use pyo3::prelude::{PyDictMethods, PyListMethods};
use pyo3::types::{PyDict, PyList};
@@ -9,7 +8,7 @@ use rust_decimal::prelude::ToPrimitive;
use rust_decimal::Decimal;
use serde_json::Value;
use zen_engine::{DecisionGraphResponse, EvaluationTrace};
use zen_expression::variable::ToVariable;
use zen_expression::variable::{RcCell, ToVariable};
use zen_expression::Variable;
use crate::value::value_to_object;
@@ -29,8 +28,8 @@ impl<'py> VariableConverter<'py> {
pub fn convert(&mut self, var: &Variable) -> PyResult<Bound<'py, PyAny>> {
let addr = match var {
Variable::Array(a) => Some(Rc::as_ptr(a) as *const () as usize),
Variable::Object(o) => Some(Rc::as_ptr(o) as *const () as usize),
Variable::Array(a) => Some(RcCell::as_ptr(a) as *const () as usize),
Variable::Object(o) => Some(RcCell::as_ptr(o) as *const () as usize),
_ => None,
};
@@ -67,7 +66,7 @@ impl<'py> VariableConverter<'py> {
let dict = PyDict::new(self.py);
let borrowed = o.borrow();
for (key, value) in borrowed.iter() {
dict.set_item(key.as_ref(), self.convert(value)?)?;
dict.set_item(key.as_str(), self.convert(value)?)?;
}
dict.into_bound_py_any(self.py)
@@ -148,8 +147,8 @@ impl PortableResponse {
fn add(nodes: &mut Vec<PNode>, memo: &mut HashMap<usize, u32>, var: &Variable) -> u32 {
let addr = match var {
Variable::Array(a) => Some(Rc::as_ptr(a) as *const () as usize),
Variable::Object(o) => Some(Rc::as_ptr(o) as *const () as usize),
Variable::Array(a) => Some(RcCell::as_ptr(a) as *const () as usize),
Variable::Object(o) => Some(RcCell::as_ptr(o) as *const () as usize),
_ => None,
};
+1 -1
View File
@@ -40,7 +40,7 @@ pub fn variable_to_object<'py>(py: Python<'py>, val: &Variable) -> PyResult<Boun
let dict = PyDict::new(py);
let b = m.borrow();
for (key, value) in b.iter() {
dict.set_item(String::from(key.as_ref()), variable_to_object(py, value)?)?;
dict.set_item(key.as_str().to_owned(), variable_to_object(py, value)?)?;
}
dict.into_bound_py_any(py)