perf: replace df_translations with hashed environment lookup#2387
Merged
Conversation
Replace the df_translations data frame (O(n) row scan per lookup) with lst_translations, a list of hashed environments keyed by language. Each environment maps English strings to translations with O(1) lookup. ~3x faster for translate_string(). Co-authored-by: Ona <no-reply@ona.com>
976d591 to
b706582
Compare
Co-authored-by: Ona <no-reply@ona.com>
Performance BenchmarkComparing main ( Each benchmark runs 5 independent rounds. The change column shows the mean % difference (negative = faster). Style functions (10k elements)
Translation (10 strings per iteration)
Pipeline benchmarks
|
Use Unicode escape (\u00B7) for the interpunct character and enc2utf8() for translation strings so they are properly marked as UTF-8 in sysdata.rda. Fixes snapshot mismatch on Windows where the native encoding is not UTF-8. Co-authored-by: Ona <no-reply@ona.com>
Add .get_language() that reads the theme environment directly instead of going through get_theme_element() which calls eval_tidy() on every invocation. The language element is always a plain string, so the eval_tidy() overhead is unnecessary. This speeds up the English (default) path by ~9% and reduces memory allocation by ~89%. Co-authored-by: Ona <no-reply@ona.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replace the
df_translationsdata frame withlst_translations, a list of hashed environments keyed by language. This changes translation lookups from O(n) row scans to O(1) hashed environment access.Also bypass
get_theme_element()in the translation functions by checking the theme environment directly via.get_language(), avoiding theeval_tidy()overhead on every call. Since the default language is English (no theme element set), this is the hot path.Benchmark (per-call cost)
Changes
data-raw/internal_data.R: Buildlst_translations(hashed environments) from the Excel source, replacingdf_translationsinsysdata.rdaR/utils-translations.R: Rewrite.translate_grab_one()to use environment lookup; add.get_language()to bypassget_theme_element()overheadR/sysdata.rda: RegeneratedHow to test