Skip to content

Commit a2954e1

Browse files
committed
UI: Enable deferred loading of the Options UI
Currently, the module is either loaded (settings are registered) or not (settings not registered = menu entry missing). With this change, the AceConfig registry setup is moved into the addon core. Ace will then be able to register the settings properly, even if the options aren't yet loaded. This not only fixes the glitch that had users confused, but also improves the "perceived" snappiness of opening the UI because most of the time is spent in Blizzard's menu code. This cost is already paid if the UI has been opened before, whereas loading the options, registering the settings tree, then creating it, and THEN opening it leads to a noticeable delay (which is likely to be blamed on Rarity, even though it's just slow Lua-C-API calls in the client's native code).
1 parent 032240e commit a2954e1

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

Core.lua

+31
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ local IsSpellKnown = _G.IsSpellKnown
111111
local CombatLogGetCurrentEventInfo = _G.CombatLogGetCurrentEventInfo
112112
local IsQuestFlaggedCompleted = _G.C_QuestLog.IsQuestFlaggedCompleted
113113
local C_Covenants = _G.C_Covenants
114+
local LoadAddOn = _G.C_AddOns.LoadAddOn
114115

115116
local COMBATLOG_OBJECT_AFFILIATION_MINE = _G.COMBATLOG_OBJECT_AFFILIATION_MINE
116117
local COMBATLOG_OBJECT_AFFILIATION_PARTY = _G.COMBATLOG_OBJECT_AFFILIATION_PARTY
@@ -147,6 +148,22 @@ do
147148

148149
function R:OnEnable()
149150
self:DoEnable()
151+
-- The Options module is disabled to reduce memory usage and loading time
152+
-- However, players can only see the menu entry once AceConfig has registered it
153+
-- Workaround: Provide a generator (function) that creates the UI only when needed
154+
LibStub("AceConfig-3.0"):RegisterOptionsTable("Rarity", function()
155+
return R:LazyLoadOptions("options")
156+
end)
157+
R.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Rarity", "Rarity")
158+
R.profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(R.db)
159+
LibStub("AceConfig-3.0"):RegisterOptionsTable("Rarity-Profiles", R.profileOptions)
160+
R.profileFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Rarity-Profiles", "Profiles", "Rarity")
161+
162+
LibStub("AceConfig-3.0"):RegisterOptionsTable("Rarity-Advanced", function()
163+
return R:LazyLoadOptions("advancedSettings")
164+
end)
165+
R.advancedSettingsFrame =
166+
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Rarity-Advanced", "Advanced", "Rarity")
150167
end
151168

152169
function R:DoEnable()
@@ -330,6 +347,20 @@ do
330347
end
331348
end
332349

350+
function Rarity:LazyLoadOptions(which)
351+
local options = R[which]
352+
if type(options) == "table" then
353+
-- This UI tree was previously generated (fast path; upfront cost already paid)
354+
return options
355+
end
356+
357+
Rarity.Profiling:StartTimer("RarityOptions: LoadAddon")
358+
LoadAddOn("Rarity_Options")
359+
Rarity.Profiling:EndTimer("RarityOptions: LoadAddon")
360+
361+
return R[which]
362+
end
363+
333364
function R:DelayedInit()
334365
self:ScanStatistics("DELAYED INIT")
335366
self:ScanCalendar("DELAYED INIT")

Core/EventHandlers.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,11 @@ function R:OnChatCommand(input)
744744
elseif strlower(input) == "tinspect" then -- TODO Document it?
745745
Rarity.Profiling:InspectAccumulatedTimes()
746746
else
747-
LoadAddOn("Rarity_Options")
748-
if R.optionsFrame then
747+
Rarity:LazyLoadOptions()
748+
if R.options then
749+
Rarity.Profiling:StartTimer("RarityOptions: OpenToCategory")
749750
Settings.OpenToCategory("Rarity")
751+
Rarity.Profiling:EndTimer("RarityOptions: OpenToCategory")
750752
else
751753
self:Print(L["The Rarity Options module has been disabled. Log out and enable it from your add-ons menu."])
752754
end

Modules/Options/Options.lua

-10
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ do
117117
R.modulesEnabled.options = true
118118

119119
R:PrepareOptions()
120-
121-
LibStub("AceConfig-3.0"):RegisterOptionsTable("Rarity", R.options)
122-
R.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Rarity", "Rarity")
123-
R.profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(R.db)
124-
LibStub("AceConfig-3.0"):RegisterOptionsTable("Rarity-Profiles", R.profileOptions)
125-
R.profileFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Rarity-Profiles", "Profiles", "Rarity")
126-
127-
LibStub("AceConfig-3.0"):RegisterOptionsTable("Rarity-Advanced", R.advancedSettings)
128-
R.advancedSettingsFrame =
129-
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Rarity-Advanced", "Advanced", "Rarity")
130120
end
131121
end
132122

0 commit comments

Comments
 (0)