If only a single integer type is needed in scripts – most of the time this is the case – it is best to avoid registering
lots of functions related to other integer types that will never be used. As a result,
Engine creation will be faster
because fewer functions need to be loaded.
If only 32-bit integers are needed – again, most of the time this is the case – turn on
Under this feature, only
i32 is supported as a built-in integer type and no others.
On 64-bit targets this may not gain much, but on certain 32-bit targets this improves performance due to 64-bit arithmetic requiring more CPU cycles to complete.
Dynamic helps performance due to better cache efficiency.
Internally, Rhai uses immutable strings instead of the Rust
String type. This is mainly to avoid excessive
cloning when passing function arguments.
Rhai’s internal string type is
Arc<String> depending on the
It is cheap to clone, but expensive to modify (a new copy of the string must be made in order to change it).
Therefore, functions taking
String parameters should use
&str (both map to
for the best performance with Rhai.
Support for closures that capture shared variables adds material overhead to script evaluation.
This is because every data access must be checked whether it is a shared value and, if so, take a read lock before reading it.
no_closure to disable closure and capturing support to optimize the hot path
because there is no need to take locks for shared data.