CpuLimit
CpuLimit reports the total and remaining CPU budget for the current Lua module. Every property is read-only.
What is actually limited
Section titled “What is actually limited”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.
Quick example
Section titled “Quick example”if CpuLimit.RemainingCpuTime < 0.1 then return -- postpone optional workendProperties
Section titled “Properties”| 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.RemainingCpuCycleslocal remainingPercent = CpuLimit.RemainingCpuTime * 100The budget decreases during execution
Section titled “The budget decreases during execution”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 calculationsendClient and Reflex server
Section titled “Client and Reflex server”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.
Write access
Section titled “Write access”CpuCycleLimit, RemainingCpuCycles, and RemainingCpuTime are getter-only. Assigning any of them raises a Lua access error.