From d0a1caa356b2186be616a6af9228a23da50cfff5 Mon Sep 17 00:00:00 2001 From: Brady Fomegne Date: Fri, 22 Mar 2024 20:58:29 +0100 Subject: [PATCH] perf(translator): increase performance In disabling some rhai features, we got an improvement of +30%. --- config/Cargo.toml | 2 +- config/src/lib.rs | 4 ---- engine/translator/Cargo.toml | 2 +- engine/translator/src/lib.rs | 2 -- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/config/Cargo.toml b/config/Cargo.toml index a887908..a21ddc8 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -17,7 +17,7 @@ rhai = ["dep:rhai"] rhai-wasm = ["rhai", "rhai/wasm-bindgen"] [dependencies] -rhai = { version = "1.17.1", optional = true, features = ["only_i32", "f32_float", "no_custom_syntax"] } +rhai = { version = "1.17.1", optional = true, features = ["only_i32", "no_float", "no_closure", "unchecked", "no_position", "no_custom_syntax"] } indexmap = { version = "2.2.5", features = ["serde"] } serde = { version = "1.0.197", features = ["derive"] } toml = { version = "0.8.10", features = ["preserve_order"] } diff --git a/config/src/lib.rs b/config/src/lib.rs index e78e4e0..36833fc 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -380,10 +380,6 @@ impl Config { let empty = IndexMap::default(); let mut engine = Engine::new(); - // allow nesting up to 50 layers of expressions/statements - // at global level, but only 10 inside function - engine.set_max_expr_depths(25, 25); - self.translators .as_ref() .unwrap_or(&empty) diff --git a/engine/translator/Cargo.toml b/engine/translator/Cargo.toml index 982c78c..2687755 100644 --- a/engine/translator/Cargo.toml +++ b/engine/translator/Cargo.toml @@ -20,7 +20,7 @@ strsim = ["dep:strsim"] serde = ["indexmap/serde", "rhai/serde"] [dependencies] -rhai = { version = "1.17.1", optional = true, features = ["only_i32", "f32_float", "no_custom_syntax"] } +rhai = { version = "1.17.1", optional = true, features = ["only_i32", "no_float", "no_closure", "unchecked", "no_position", "no_custom_syntax"] } indexmap = { version = "2.2.5" } strsim = { version = "0.11.0", optional = true } diff --git a/engine/translator/src/lib.rs b/engine/translator/src/lib.rs index cdf4e5a..d706900 100644 --- a/engine/translator/src/lib.rs +++ b/engine/translator/src/lib.rs @@ -229,8 +229,6 @@ impl Translator { /// } /// "#; /// let mut engine = Engine::new(); - /// // confer: https://rhai.rs/book/safety/max-stmt-depth.html - /// engine.set_max_expr_depths(25, 25); /// let date_translator = engine.compile(date_translator).unwrap(); /// /// // We build the translator.