Skip to content

Commit a613a66

Browse files
committed
proxy optimization
if a part-finding function fails repeatedly to find a valid part to cache, stop searching after 250 tries
1 parent b106e42 commit a613a66

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lua/pac3/core/client/parts/proxy.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function PART:GetOrFindCachedPart(uid_or_name)
108108
self.found_cached_parts = self.found_cached_parts or {}
109109
if self.found_cached_parts[uid_or_name] then self.erroring_cached_parts[uid_or_name] = nil return self.found_cached_parts[uid_or_name] end
110110
if self.erroring_cached_parts[uid_or_name] then return end
111+
if self.bad_uid_search and self.bad_uid_search > 250 then return end
111112

112113
local owner = self:GetPlayerOwner()
113114
part = pac.GetPartFromUniqueID(pac.Hash(owner), uid_or_name) or pac.FindPartByPartialUniqueID(pac.Hash(owner), uid_or_name)
@@ -119,6 +120,11 @@ function PART:GetOrFindCachedPart(uid_or_name)
119120
end
120121
if not part:IsValid() then
121122
self.erroring_cached_parts[uid_or_name] = true
123+
self.bad_uid_search = self.bad_uid_search or 0
124+
self.bad_uid_search = self.bad_uid_search + 1
125+
if self:GetPlayerOwner() == LocalPlayer() then
126+
pace.FlashNotification("performance warning! " .. tostring(self) .. " keeps searching for parts not finding anything! " .. tostring(uid_or_name) .. " may be unused!")
127+
end
122128
else
123129
self.found_cached_parts[uid_or_name] = part
124130
return part
@@ -1596,6 +1602,10 @@ local allowed = {
15961602

15971603
function PART:SetExpression(str, slot)
15981604
str = string.Trim(str,"\n")
1605+
self.bad_uid_search = nil
1606+
self.found_cached_parts = {}
1607+
self.erroring_cached_parts = {}
1608+
15991609
if self == pace.current_part and (pace.ActiveSpecialPanel and pace.ActiveSpecialPanel.luapad) and str ~= "" then
16001610
--update luapad text if we update the expression from the properties
16011611
if slot == pace.ActiveSpecialPanel.luapad.keynumber then --this check prevents cross-contamination

0 commit comments

Comments
 (0)