diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c5a8da..ac740fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ - **[Lua 5.0 - Modulo Operator]** Routed the nine arithmetic `%` modulo sites (daily/weekly quest flag tests, Darkmoon Faire cycle math, learner GUID/flag math, race/class flag tests) through the existing `math.mod` shim. Lua 5.0 has no `%` operator outside string formatting, so this was a parse error on Vanilla 1.12 clients; the addon now parses on 5.0 through Retail. - **[Lua 5.0 - Options Tab Tables]** Fixed `QuestieOptions.tabs.{auto,dbm,icons,nameplate}` being initialized with `{...}` instead of `{}`. On Lua 5.1 this silently captured the addon varargs into the table; on Lua 5.0 it is a parse error. All sibling tabs already used `{}`, and `Initialize` repopulates the table, so there is no behavioral change. +### Performance + +> Measured optimizations being cherry-picked from `phase3-measured-perf` and in-game tested one at a time on top of 1.6.4. + +- **[l10n - Literal Translation Cache]** Added a locale-keyed cache for no-argument translation lookups so repeated literal keys resolve without redoing the lookup chain. The cache is reset on locale change and when locale overrides are applied. (Ported from `phase3-measured-perf` 970dd88.) + ## [Unreleased] - Performance Refactor Branches ### Performance diff --git a/Localization/l10n.lua b/Localization/l10n.lua index cf5bfe2..7877c62 100644 --- a/Localization/l10n.lua +++ b/Localization/l10n.lua @@ -12,6 +12,7 @@ l10n.npcNameLookup = {} l10n.objectNameLookup = {} l10n.objectLookup = {} l10n.questLookup = {} +l10n.translationCache = {} ---@type QuestieDB local QuestieDB = QuestieLoader:ImportModule("QuestieDB") @@ -30,6 +31,10 @@ local supportedLocals = { ['koKR'] = true, } +local function ResetTranslationCache() + l10n.translationCache = {} +end + function l10n:InitializeLocaleOverride() local overridingLocale = QUESTIE_LOCALES_OVERRIDE.locale supportedLocals[overridingLocale] = true @@ -45,6 +50,8 @@ function l10n:InitializeLocaleOverride() l10n.translations[id][overridingLocale] = false end end + + ResetTranslationCache() end ---@param zoneName string @@ -193,28 +200,42 @@ function _l10n:translate(key, ...) key = tostring(key) local argCount = select("#", ...) if argCount == 0 then + local localeCache = l10n.translationCache[locale] + if localeCache and localeCache[key] ~= nil then + return localeCache[key] + end + if not localeCache then + localeCache = {} + l10n.translationCache[locale] = localeCache + end + 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 + localeCache[key] = key 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 + localeCache[key] = key return key end if translationValue == true then -- Fallback to enUS which is the key + localeCache[key] = 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 + localeCache[key] = key return key end + localeCache[key] = translationValue return translationValue end @@ -283,6 +304,8 @@ function l10n:SetUILocale(lang) else locale = _l10n:GetFallbackLocale(GetLocale()) end + + ResetTranslationCache() end function l10n:GetUILocale() diff --git a/docs/changelog.html b/docs/changelog.html index 0da77cd..d36a46f 100644 --- a/docs/changelog.html +++ b/docs/changelog.html @@ -218,6 +218,11 @@
% modulo sites (daily/weekly quest flag tests, Darkmoon Faire cycle math, learner GUID/flag math, race/class flag tests) through the existing math.mod shim. Lua 5.0 has no % operator outside string formatting, so this was a parse error on Vanilla 1.12 clients; the addon now parses on 5.0 through Retail.QuestieOptions.tabs.{auto,dbm,icons,nameplate} being initialized with {...} instead of {}. On Lua 5.1 this silently captured the addon varargs into the table; on Lua 5.0 it is a parse error. All sibling tabs already used {}, and Initialize repopulates the table, so there is no behavioral change.Measured optimizations being cherry-picked from phase3-measured-perf and in-game tested one at a time on top of 1.6.4.
phase3-measured-perf 970dd88.)QuestieCompat, hooked at init). Blizzard POIs still appear for quests Questie does not cover, but no longer stack on top of Questie's own objective icons.