Skip to content

Commit 5168420

Browse files
committed
optimize event uid search
catastrophic lag occurs when part search repeatedly fails, severity scaling with localparts size it was already handled with proxy but now I transferred it to event
1 parent 5ca3c51 commit 5168420

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lua/pac3/core/client/parts/event.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,11 @@ end
317317

318318
function PART:GetOrFindCachedPart(uid_or_name)
319319
local part = nil
320-
local existing_part = self.found_cached_parts[uid_or_name]
321-
if existing_part then
322-
if existing_part ~= NULL and existing_part:IsValid() then
323-
return existing_part
324-
end
325-
end
320+
self.erroring_cached_parts = {}
321+
self.found_cached_parts = self.found_cached_parts or {}
322+
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
323+
if self.erroring_cached_parts[uid_or_name] then return end
324+
if self.bad_uid_search and self.bad_uid_search > 250 then return end
326325

327326
local owner = self:GetPlayerOwner()
328327
part = pac.GetPartFromUniqueID(pac.Hash(owner), uid_or_name) or pac.FindPartByPartialUniqueID(pac.Hash(owner), uid_or_name)
@@ -332,7 +331,14 @@ function PART:GetOrFindCachedPart(uid_or_name)
332331
self.found_cached_parts[uid_or_name] = part
333332
return part
334333
end
335-
if part:IsValid() then
334+
if not part:IsValid() then
335+
self.erroring_cached_parts[uid_or_name] = true
336+
self.bad_uid_search = self.bad_uid_search or 0
337+
self.bad_uid_search = self.bad_uid_search + 1
338+
if self:GetPlayerOwner() == LocalPlayer() then
339+
pace.FlashNotification("performance warning! " .. tostring(self) .. " keeps searching for parts not finding anything! " .. tostring(uid_or_name) .. " may be unused!")
340+
end
341+
else
336342
self.found_cached_parts[uid_or_name] = part
337343
return part
338344
end
@@ -2893,7 +2899,7 @@ PART.OldEvents = {
28932899
local true_count = 0
28942900
for i,uid in ipairs(uid_splits) do
28952901
local part = self:GetOrFindCachedPart(uid)
2896-
if part:IsValid() then
2902+
if IsValid(part) then
28972903
local raw = part.raw_event_condition
28982904
local b = false
28992905
if ignore_inverts then

0 commit comments

Comments
 (0)