Skip to content

perf(translator): increase performance#278

Merged
pythonbrad merged 1 commit into
mainfrom
patch_translator
Jun 23, 2026
Merged

perf(translator): increase performance#278
pythonbrad merged 1 commit into
mainfrom
patch_translator

Conversation

@pythonbrad

@pythonbrad pythonbrad commented Jun 23, 2026

Copy link
Copy Markdown
Member

Description

  • This commit reduces memory allocations as possible.

Related issues

Changes

  • Stored Engine in the structure Translator reducing the construction and discarding of the rhai runtime on every translate call.
  • Eliminated Predicate construction before condition is checked.
  • Fixed a bug in the building of the remaining_code.
  • Replaced sort_by by sort_unstable_by to reduce memory usage.

Additional changes

Fixed potential panic in the comparison between the first characters.

Dataset

// Prepares the dictionary.
let mut dictionary = IndexMap::new();
dictionary.insert("jump".to_string(), vec!["sauter".to_string()]);
// Why a user want to do it? 
dictionary.insert("😎".to_string(), vec!["cool".to_string()]);

Error

thread 'main' (103661) panicked at engine/translator/src/lib.rs:345:75:
end byte index 1 is not a char boundary; it is inside '😎' (bytes 0..4 of string)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@pythonbrad pythonbrad self-assigned this Jun 23, 2026
This commit reduces memory allocations as possible and introduces the
following changes:

- Stored `Engine` in the structure `Translator` reducing the
  contruction and discarding of the rhai runtime on every translate
call.
- Eliminated `Predicate` construction before condition is checked.
- Fixed a bug in the building of the `remaining_code`.
- Fixed potential panic in the comparaison between the first characters.
- Replaced `sort_by` by `sort_unstable_by` to reduce memory usage.
@pythonbrad pythonbrad merged commit 1a51e7f into main Jun 23, 2026
5 checks passed
@pythonbrad pythonbrad deleted the patch_translator branch June 23, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant