Instruction budget
A limit on how many Lua instructions one call from Hazel into the config may run. A loop that never ends is stopped instead of freezing the compositor.
What has a budget
These get wm.instruction_budget instructions per call, 500000 by default:
- loading the config
- each event handler, one at a time
- each timer callback
- each
Processand clipboard callback - each chunk from the socket
A handler can set off another one straight away, for example by assigning a property that fires an event. The inner handler shares the outer call's budget.
- Only Lua instructions count, not time spent inside Hazel's own functions.
- A call can run up to about 1000 instructions past the limit before it is stopped.
Running over
A call that runs over is stopped with an error like this, followed by a traceback of where it was:
text
timer ran over its instruction budget of 500000 (wm.instruction_budget) and was stopped- The error is logged. For a socket chunk it is sent back instead.
pcall,xpcalland coroutines can't catch it.- Nothing is unregistered. The handler or timer runs again next time, with a fresh budget.
- A config load that runs over fails like any other load error. See Reloading.
Then overrun fires on wm, with a budget of its own. An overrun handler that runs over doesn't fire overrun again.
lua
wm:on("overrun", function(info)
local where = info.traceback:match("stack traceback:\n%s*([^\n]*)") or info.traceback
print("stopped " .. info.source .. " at " .. where)
end)Changing it
Assign wm.instruction_budget from the config.
- Every load starts at the default again. Set it at the top of the config if loading needs more.
Errors for less than 1000.
lua
wm.instruction_budget = 2000000