Performance mode
Virtualised code runs through an interpreter, so very hot code such as RenderStepped loops, raycasts and camera math can drop frames. Run just those functions natively and keep everything else protected.
Video: Performance mode and fixing slow scripts
Run a function natively
Wrap the function literal in CTN_NO_VIRTUALIZE. It runs as a normal Luau closure at full speed; the rest of the script stays virtualised.
local RunService = game:GetService("RunService")
local onFrame = CTN_NO_VIRTUALIZE(function(dt)
local cam = workspace.CurrentCamera
return cam.CFrame.LookVector * (dt * 60)
end)
RunService.RenderStepped:Connect(onFrame)
Let the editor do it: When you build, the editor scans for hot loops and offers to wrap them for you.
Keep in mind
- Wrap only the hot path. Native code is not virtualised, so keep secrets out of it.
- The macro must wrap a function literal directly.
- Legacy Cortex builds use CRX_NO_VIRTUALIZE instead. See Legacy macros.