Skip to content

CpuLimit

CpuLimit reports the total and remaining CPU budget for the current Lua module. Every property is read-only.

This is the Lua VM execution budget, not the computer’s processor usage percentage. The runtime gives the current Lua call a conditional cycle limit and reduces the remainder as instructions execute. When the budget is exhausted, module-limit handling may yield or terminate execution.

The values help heavy loops regulate their work. Reading CpuLimit does not speed anything up or reserve additional time.

if CpuLimit.RemainingCpuTime < 0.1 then
return -- postpone optional work
end
Property Type Access Description
CpuCycleLimit integer get Maximum CPU-cycle budget for the module’s current execution.
RemainingCpuCycles integer get Remaining CPU-cycle budget.
RemainingCpuTime number get Remaining budget fraction, from 0 to 1.
local usedCycles = CpuLimit.CpuCycleLimit - CpuLimit.RemainingCpuCycles
local remainingPercent = CpuLimit.RemainingCpuTime * 100

These values describe the current remainder, not a permanent device characteristic. In a test callback, a simple 100-iteration loop reduced RemainingCpuCycles.

Read the remainder immediately before an expensive optional operation:

if CpuLimit.RemainingCpuTime >= 0.2 then
-- Additional calculations
end

The API works in both contexts, but their limits differ significantly. During testing, one client module received 880000000 cycles, while a Reflex server.lua received 1999000.

CpuCycleLimit, RemainingCpuCycles, and RemainingCpuTime are getter-only. Assigning any of them raises a Lua access error.