Skip to content

Commit dcc94ec

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 b3c6114 commit dcc94ec

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
@@ -750,4 +750,54 @@ describe("TestRadiusJewelStatDiff", function()
750750
"temporary tooltip specs should still refresh jewel socket distances used by calc")
751751
end)
752752

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

src/Classes/ItemsTab.lua

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,6 +3798,37 @@ local function itemChangesPassiveTreeRadius(item)
37983798
and (item.jewelData.conqueredBy or item.jewelData.intuitiveLeapLike or item.jewelData.impossibleEscapeKeystone))
37993799
end
38003800

3801+
local function getStoredItemId(itemsTab, item)
3802+
if not item then
3803+
return ""
3804+
end
3805+
local itemId = item.id
3806+
if itemId and itemsTab.items[itemId] == item then
3807+
return tostring(itemId)
3808+
end
3809+
end
3810+
3811+
local function getJewelComparisonOutputCache(itemsTab)
3812+
local outputRevision = itemsTab.build and itemsTab.build.outputRevision or 0
3813+
local cache = itemsTab.jewelComparisonOutputCache
3814+
if not cache or cache.outputRevision ~= outputRevision then
3815+
cache = {
3816+
outputRevision = outputRevision,
3817+
outputs = { },
3818+
}
3819+
itemsTab.jewelComparisonOutputCache = cache
3820+
end
3821+
return cache
3822+
end
3823+
3824+
local function getJewelComparisonOutputCacheKey(itemsTab, compareSlot, replacementItem)
3825+
local replacementItemId = getStoredItemId(itemsTab, replacementItem)
3826+
if not replacementItemId then
3827+
return
3828+
end
3829+
return tostring(compareSlot.slotName) .. ":" .. tostring(compareSlot.nodeId or "") .. ":" .. tostring(compareSlot.selItemId or "") .. ":" .. replacementItemId
3830+
end
3831+
38013832
-- Radius jewels can change conquered nodes and orphaned allocations, so compare
38023833
-- against a rebuilt spec instead of approximating the diff with removeNodes.
38033834
-- Keep this list in sync with PassiveSpec's constructor, Init, and Select*
@@ -4562,13 +4593,27 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
45624593

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

4565-
local function getReplacedItemAndOutput(compareSlot, selItem, useJewelComparisonSpecCache)
4596+
local function getReplacedItemAndOutput(compareSlot, selItem, useJewelComparisonSpecCache, useJewelComparisonOutputCache)
45664597
selItem = selItem or self.items[compareSlot.selItemId]
45674598
local override = { repSlotName = compareSlot.slotName, repItem = item ~= selItem and item or nil }
4599+
local outputCache
4600+
local outputCacheKey
45684601
if compareSlot.nodeId and (itemChangesPassiveTreeRadius(selItem) or itemChangesPassiveTreeRadius(item)) then
4602+
if useJewelComparisonOutputCache then
4603+
outputCacheKey = getJewelComparisonOutputCacheKey(self, compareSlot, override.repItem)
4604+
if outputCacheKey then
4605+
outputCache = getJewelComparisonOutputCache(self)
4606+
if outputCache.outputs[outputCacheKey] then
4607+
return selItem, outputCache.outputs[outputCacheKey]
4608+
end
4609+
end
4610+
end
45694611
override.spec = buildSpecForJewelComparison(self, compareSlot, override.repItem, useJewelComparisonSpecCache)
45704612
end
45714613
local output = calcFunc(override)
4614+
if outputCacheKey then
4615+
outputCache.outputs[outputCacheKey] = output
4616+
end
45724617
return selItem, output
45734618
end
45744619
local function addCompareForSlot(compareSlot, selItem, output, useJewelComparisonSpecCache)
@@ -4610,7 +4655,7 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode, maxWidth)
46104655
local slots = {}
46114656
for _, slotEntry in ipairs(slotCandidates) do
46124657
if not isLimitedUniqueAtLimit or slotEntry.isSameUnique then
4613-
local _, output = getReplacedItemAndOutput(slotEntry.compareSlot, slotEntry.selItem)
4658+
local _, output = getReplacedItemAndOutput(slotEntry.compareSlot, slotEntry.selItem, nil, true)
46144659
slotEntry.output = output
46154660
table.insert(slots, slotEntry)
46164661
end

0 commit comments

Comments
 (0)