From c7af49d8bd5d83da023c02fa021cf4f526c07277 Mon Sep 17 00:00:00 2001 From: Xurkon Date: Mon, 8 Jun 2026 16:25:09 -0500 Subject: [PATCH] perf(l10n): add zero-arg fast path to translate _l10n:translate now short-circuits the common no-argument case (select('#', ...) == 0), returning the translation directly and skipping the {...} allocation, the tostring loop, and safeFormat. Behavior matches the slow path: a successful no-arg lookup already returned the raw value, and missing/invalid entries fall back to the key. Cherry-picked from phase2-lua50-sweep. --- CHANGELOG.md | 1 + Localization/l10n.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c667df..bb75203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - **[QuestieComms - Disable Gate Fix]** Scoped the comms enable helper so the disable switch no longer calls a nil global and every send/process entry point consistently respects the setting. - **[Arrow - Low-End Performance Controls]** Added live Arrow update throttles to reduce repeated nearest-target and coordinate work while preserving existing arrow behavior. - **[Measured Hot Paths - Phase 3]** Landed measured optimizations on the phase 3 branch for literal localization caching, available quest redraw batching, `QuestieDB.IsDoable` batch reads, hot profile aliases, `GetTime()` hoists, NPC fallback lookup caching, and validate-cache allocation cleanup. +- **[Localization - Zero-Arg Translate Fast Path]** `_l10n:translate` now short-circuits the common no-argument case (`select("#", ...) == 0`) and returns the translation directly, skipping the `{...}` table allocation, the `tostring` coercion loop, and the `safeFormat` call. The vast majority of translation lookups pass no format arguments, so this avoids per-call garbage on a hot path. Behavior matches the existing slow path: a successful no-arg lookup already returned the raw value, and the missing/invalid-entry branches fall back to the key. Cherry-picked from phase2-lua50-sweep. ### Bug Fixes diff --git a/Localization/l10n.lua b/Localization/l10n.lua index 1660fc1..cf5bfe2 100644 --- a/Localization/l10n.lua +++ b/Localization/l10n.lua @@ -191,6 +191,33 @@ function _l10n:translate(key, ...) return "" end key = tostring(key) + local argCount = select("#", ...) + if argCount == 0 then + local translationEntry = l10n.translations[key] + if not translationEntry then + if (Questie.db.profile.debugEnabled) then Questie:Debug(Questie.DEBUG_ELEVATED, "ERROR: Translations for '" .. tostring(key) .. "' are missing completely!") end + return key + end + + local translationValue = translationEntry[locale] + if (not translationValue) then + if (Questie.db.profile.debugEnabled) then Questie:Debug(Questie.DEBUG_ELEVATED, "ERROR: Translations for '" .. tostring(key) .. "' are missing the entry for language" , locale, "!") end + return key + end + + if translationValue == true then + -- Fallback to enUS which is the key + return key + end + + if type(translationValue) ~= "string" then + if (Questie.db.profile.debugEnabled) then Questie:Debug(Questie.DEBUG_ELEVATED, "ERROR: Translation for '" .. tostring(key) .. "' is not a string!") end + return key + end + + return translationValue + end + local args = {...} for i, v in ipairs(args) do