From 1d5cd8264be9b2999443186a1ab38f461e3822e8 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 9 Oct 2026 23:20:49 +0300 Subject: [PATCH 1/3] Change global quota kill mechanism --- lua/entities/gmod_wire_expression2/init.lua | 34 +++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/init.lua b/lua/entities/gmod_wire_expression2/init.lua index 944d2c7a77..b65ab567a6 100644 --- a/lua/entities/gmod_wire_expression2/init.lua +++ b/lua/entities/gmod_wire_expression2/init.lua @@ -422,32 +422,28 @@ E2Lib.PlayerChips = E2Lib.PlayerChips or setmetatable({}, GlobalChips) hook.Add("Think", "E2_Think", function() local global_time = 0 + local worst_ply, worst_time = nil, 0 - if e2_timequota > 0 then - for ply, chips in pairs(E2Lib.PlayerChips) do - global_time = global_time + chips:checkCpuTime() - end - else - for ply, chips in pairs(E2Lib.PlayerChips) do - global_time = global_time + chips:getTotalTime() + for ply, chips in pairs(E2Lib.PlayerChips) do + local time = e2_timequota > 0 and chips:checkCpuTime() or chips:getTotalTime() + global_time = global_time + time + + if time > worst_time then + worst_ply, worst_time = ply, time end end - if e2_globalmax > 0 and global_time > e2_globalmax then - -- It will be faster to just iterate over all chips from now on - local chips = ents.FindByClass("gmod_wire_expression2") + if e2_globalmax > 0 and global_time > e2_globalmax and worst_ply then + local chips = E2Lib.PlayerChips[worst_ply] while global_time > e2_globalmax do - local max_chip, max_time = E2Lib.PlayerChips:findMaxTimeChip(chips) + local chip, chip_time = chips:findMaxTimeChip() + if not chip then break end - if max_chip then - global_time = global_time - max_time - max_chip:Error("Expression 2 (" .. max_chip.name .. "): Global time quota exceeded", "global time quota exceeded") - max_chip:Destruct() - else - -- It shouldn't happen, but if something breaks, it will prevent an infinity loop - break - end + chip:Error("Expression 2 (" .. chip.name .. "): Global time quota exceeded", "global time quota exceeded") + chip:Destruct() + + global_time = global_time - chip_time end end end) From 4d6c4361079690af868e2e9e9d4c10a5197e7551 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 9 Oct 2026 23:28:22 +0300 Subject: [PATCH 2/3] Kill only one chip per tick to smooth it --- lua/entities/gmod_wire_expression2/init.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/init.lua b/lua/entities/gmod_wire_expression2/init.lua index b65ab567a6..0aeb3e63f4 100644 --- a/lua/entities/gmod_wire_expression2/init.lua +++ b/lua/entities/gmod_wire_expression2/init.lua @@ -434,16 +434,11 @@ hook.Add("Think", "E2_Think", function() end if e2_globalmax > 0 and global_time > e2_globalmax and worst_ply then - local chips = E2Lib.PlayerChips[worst_ply] + local max_chip, max_time = E2Lib.PlayerChips[worst_ply]:findMaxTimeChip() - while global_time > e2_globalmax do - local chip, chip_time = chips:findMaxTimeChip() - if not chip then break end - - chip:Error("Expression 2 (" .. chip.name .. "): Global time quota exceeded", "global time quota exceeded") - chip:Destruct() - - global_time = global_time - chip_time + if max_chip then + max_chip:Error("Expression 2 (" .. max_chip.name .. "): Global time quota exceeded", "global time quota exceeded") + max_chip:Destruct() end end end) From 77b92ad0686e7f6c15799ffcc06145f91097b5d2 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Fri, 9 Oct 2026 23:33:03 +0300 Subject: [PATCH 3/3] Lint pass + remove now unused --- lua/entities/gmod_wire_expression2/init.lua | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/init.lua b/lua/entities/gmod_wire_expression2/init.lua index 0aeb3e63f4..4b220926cb 100644 --- a/lua/entities/gmod_wire_expression2/init.lua +++ b/lua/entities/gmod_wire_expression2/init.lua @@ -399,25 +399,6 @@ function GlobalChips:remove(remove_chip) end end -function GlobalChips:findMaxTimeChip(chips) - local max_chip, max_time = nil, 0 - - for _, chip in ipairs(chips) do - local tab = chip:GetTable() - if tab.error then continue end - - local context = tab.context - if not context then continue end - - if context.timebench > max_time then - max_time = context.timebench - max_chip = chip - end - end - - return max_chip, max_time -end - E2Lib.PlayerChips = E2Lib.PlayerChips or setmetatable({}, GlobalChips) hook.Add("Think", "E2_Think", function() @@ -434,7 +415,7 @@ hook.Add("Think", "E2_Think", function() end if e2_globalmax > 0 and global_time > e2_globalmax and worst_ply then - local max_chip, max_time = E2Lib.PlayerChips[worst_ply]:findMaxTimeChip() + local max_chip = E2Lib.PlayerChips[worst_ply]:findMaxTimeChip() if max_chip then max_chip:Error("Expression 2 (" .. max_chip.name .. "): Global time quota exceeded", "global time quota exceeded")