Skip to content

Commit

Permalink
perf(translator): increase performance (#204)
Browse files Browse the repository at this point in the history
In disabling some rhai features, we got an improvement of ~30%.
  • Loading branch information
pythonbrad authored Mar 22, 2024
1 parent 9aca6f3 commit aa0e409
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 1 addition & 5 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,7 @@ impl Config {
fs: &impl FileSystem,
) -> Result<IndexMap<String, AST>> {
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);
let engine = Engine::new();

self.translators
.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion engine/translator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 0 additions & 2 deletions engine/translator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit aa0e409

Please sign in to comment.