Skip to content

Commit 7ebd706

Browse files
committed
Cache radius jewel tooltip outputs
Reuse full radius jewel comparison outputs while the build output revision is unchanged. This reduces repeated Compare-tab hover work for slotOnlyTooltips=OFF without caching cloned specs or changing comparison behavior.
1 parent ca38815 commit 7ebd706

2 files changed

Lines changed: 97 additions & 2 deletions

File tree

spec/System/TestRadiusJewelStatDiff_spec.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,4 +753,54 @@ describe("TestRadiusJewelStatDiff", function()
753753
"temporary tooltip specs should still refresh jewel socket distances used by calc")
754754
end)
755755

756+
it("AddItemTooltip reuses full radius jewel comparison outputs until output changes", function()
757+
local spec, sockets = setupAllocatedSockets(2)
758+
759+
local item = newCustomLeapJewel("Cached Full Leap")
760+
local slot = equipJewelInSocket(item, sockets[1])
761+
spec:BuildAllDependsAndPaths()
762+
runCallback("OnFrame")
763+
764+
local originalSlotOnlyTooltips = main.slotOnlyTooltips
765+
main.slotOnlyTooltips = false
766+
build.itemsTab.jewelComparisonOutputCache = nil
767+
build.itemsTab.targetedJewelComparisonSpecCache = nil
768+
769+
local originalGetMiscCalculator = build.calcsTab.GetMiscCalculator
770+
local calcCalls = 0
771+
build.calcsTab.GetMiscCalculator = function(self, ...)
772+
local calcFunc, calcBase = originalGetMiscCalculator(self, ...)
773+
return function(...)
774+
calcCalls = calcCalls + 1
775+
return calcFunc(...)
776+
end, calcBase
777+
end
778+
779+
local ok, err = pcall(function()
780+
local tooltip = new("Tooltip")
781+
build.itemsTab:AddItemTooltip(tooltip, item, slot)
782+
local firstPassCalcCalls = calcCalls
783+
assert.is_true(firstPassCalcCalls > 0,
784+
"full radius jewel tooltip should calculate outputs on first pass")
785+
786+
tooltip = new("Tooltip")
787+
build.itemsTab:AddItemTooltip(tooltip, item, slot)
788+
local secondPassCalcCalls = calcCalls - firstPassCalcCalls
789+
assert.is_true(secondPassCalcCalls < firstPassCalcCalls,
790+
"full radius jewel tooltip should reuse cached radius outputs on second pass")
791+
792+
build.outputRevision = build.outputRevision + 1
793+
local beforeInvalidationCalcCalls = calcCalls
794+
tooltip = new("Tooltip")
795+
build.itemsTab:AddItemTooltip(tooltip, item, slot)
796+
assert.is_true(calcCalls - beforeInvalidationCalcCalls > secondPassCalcCalls,
797+
"full radius jewel output cache should reset when output changes")
798+
end)
799+
build.calcsTab.GetMiscCalculator = originalGetMiscCalculator
800+
main.slotOnlyTooltips = originalSlotOnlyTooltips
801+
if not ok then
802+
error(err)
803+
end
804+
end)
805+
756806
end)

src/Classes/ItemsTab.lua

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,6 +4228,37 @@ local function itemChangesPassiveTree(item)
42284228
and (item.jewelData.intuitiveLeapLike or item.jewelData.impossibleEscapeKeystone)))
42294229
end
42304230

4231+
local function getStoredItemId(itemsTab, item)
4232+
if not item then
4233+
return ""
4234+
end
4235+
local itemId = item.id
4236+
if itemId and itemsTab.items[itemId] == item then
4237+
return tostring(itemId)
4238+
end
4239+
end
4240+
4241+
local function getJewelComparisonOutputCache(itemsTab)
4242+
local outputRevision = itemsTab.build and itemsTab.build.outputRevision or 0
4243+
local cache = itemsTab.jewelComparisonOutputCache
4244+
if not cache or cache.outputRevision ~= outputRevision then
4245+
cache = {
4246+
outputRevision = outputRevision,
4247+
outputs = { },
4248+
}
4249+
itemsTab.jewelComparisonOutputCache = cache
4250+
end
4251+
return cache
4252+
end
4253+
4254+
local function getJewelComparisonOutputCacheKey(itemsTab, compareSlot, replacementItem)
4255+
local replacementItemId = getStoredItemId(itemsTab, replacementItem)
4256+
if not replacementItemId then
4257+
return
4258+
end
4259+
return tostring(compareSlot.slotName) .. ":" .. tostring(compareSlot.nodeId or "") .. ":" .. tostring(compareSlot.selItemId or "") .. ":" .. replacementItemId
4260+
end
4261+
42314262
-- These jewels can replace passive nodes or disconnect allocated passives, so
42324263
-- rebuild the passive tree before comparing their stats.
42334264
-- Keep this list in sync with PassiveSpec's constructor, Init, and Select*
@@ -5079,13 +5110,27 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
50795110

50805111
tooltip:AddLine(14, colorCodes.TIP .. "Tip: Press Ctrl+D"..itemTabHint.." to disable the display of stat differences.")
50815112

5082-
local function getReplacedItemAndOutput(compareSlot, selItem, useJewelComparisonSpecCache)
5113+
local function getReplacedItemAndOutput(compareSlot, selItem, useJewelComparisonSpecCache, useJewelComparisonOutputCache)
50835114
selItem = selItem or self.items[compareSlot.selItemId]
50845115
local override = { repSlotName = compareSlot.slotName, repItem = item ~= selItem and item or nil }
5116+
local outputCache
5117+
local outputCacheKey
50855118
if compareSlot.nodeId and (itemChangesPassiveTree(selItem) or itemChangesPassiveTree(item)) then
5119+
if useJewelComparisonOutputCache then
5120+
outputCacheKey = getJewelComparisonOutputCacheKey(self, compareSlot, override.repItem)
5121+
if outputCacheKey then
5122+
outputCache = getJewelComparisonOutputCache(self)
5123+
if outputCache.outputs[outputCacheKey] then
5124+
return selItem, outputCache.outputs[outputCacheKey]
5125+
end
5126+
end
5127+
end
50865128
override.spec = buildSpecForJewelComparison(self, compareSlot, override.repItem, useJewelComparisonSpecCache)
50875129
end
50885130
local output = calcFunc(override)
5131+
if outputCacheKey then
5132+
outputCache.outputs[outputCacheKey] = output
5133+
end
50895134
return selItem, output
50905135
end
50915136
local function addCompareForSlot(compareSlot, selItem, output, useJewelComparisonSpecCache)
@@ -5127,7 +5172,7 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
51275172
local slots = {}
51285173
for _, slotEntry in ipairs(slotCandidates) do
51295174
if not isLimitedUniqueAtLimit or slotEntry.isSameUnique then
5130-
local _, output = getReplacedItemAndOutput(slotEntry.compareSlot, slotEntry.selItem)
5175+
local _, output = getReplacedItemAndOutput(slotEntry.compareSlot, slotEntry.selItem, nil, true)
51315176
slotEntry.output = output
51325177
table.insert(slots, slotEntry)
51335178
end

0 commit comments

Comments
 (0)