Skip to main content
TRACK B·PRODUCTION ENGINEERING·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

Measure performance with resmon and the profiler

At 60 frames per second one frame is about 16.7 ms, shared by the game and every resource. A Wait(0) loop is not automatically bad; its body runs every frame, so unnecessary work inside it is the problem. This lesson teaches you to measure before and after instead of promising made-up benchmark numbers. You measure with resmon first, then reach for the built-in profiler when resmon says something is slow but does not say why.

You'll learn
resmon, CreateThread, adaptive Wait tuning, GetGameTimer throttling, and how to capture and read a profiler trace to find the exact line costing you frames
Time
~34 minutes
Prereqs
Lessons 13 (threads) and 14 (server vs client)
Outcome
You measure an idle and near-marker baseline, prove the loop sleeps when its work is not visible, and capture a profiler trace that names the exact function eating your frame budget
RED: writing high-performance Lua for FiveM.
BEFORE YOU START

Build it

Make the resource folder

The server has one folder for this lesson.

Inside your server's resources folder, create this folder:

code
resources/qu_performance_resmon

Create the files

Every file named in the manifest exists.

Create this exact file layout:

code
resources/qu_performance_resmon/
fxmanifest.lua
client.lua

Write fxmanifest.lua

FiveM knows which files to load.

Open fxmanifest.lua and paste this:

code
fx_version 'cerulean'
game 'gta5'

client_script 'client.lua'

There is no lua54 'yes' line. As of June 2025 that directive is deprecated and ignored: Lua 5.4 is the only Lua runtime now, so you leave it out.

Write the lesson code

The topic is now represented by runnable code.

Open client.lua and paste this. It draws a marker only when enabled and nearby, and otherwise sleeps. Record your own resmon numbers because cost depends on hardware, client build, and the work inside the loop.

code
local markerOn = false
local markerCoords = vector3(-269.0, -955.0, 31.2) -- near Legion Square

RegisterCommand('resmontoggle', function()
markerOn = not markerOn
print('[qu_performance_resmon] marker on: ' .. tostring(markerOn))
end, false)

CreateThread(function()
while true do
    local sleep = 1000 -- far away or off: sleep a full second

    if markerOn then
        local ped = PlayerPedId()
        local coords = GetEntityCoords(ped)
        local dist = #(coords - markerCoords)

        if dist < 20.0 then
            sleep = 0 -- close enough to see it: run every frame
            DrawMarker(1, markerCoords.x, markerCoords.y, markerCoords.z - 1.0,
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.3,
                0, 180, 255, 120, false, false, 2, false, nil, nil, false)
        end
    end

    Wait(sleep)
end
end)

Start and test it

The expected proof appears in the correct console.

Open server.cfg and add this line:

code
ensure qu_performance_resmon

Save, then run this in the txAdmin Live Console (the FXServer.exe window, or the txAdmin Live Console -- NOT the in-game F8 console):

code
restart qu_performance_resmon

resmon is a developer-only command. If you launch FiveM normally it answers Access denied for command resmon. Enable developer mode first: right-click your FiveM shortcut, choose Properties, and add +set moo 31337 to the end of the Target field (or run a non-production update channel such as Beta/Latest). Restart FiveM, join the server, open the developer console with F8, and turn on the client resource monitor:

code
resmon 1

Find qu_performance_resmon in the list. With the marker off, its cost sits near 0.00 ms. Now run the command from the F8 console:

code
resmontoggle

You will see the print confirming the toggle. Teleport or walk to Legion Square (around -269, -955) and watch the cost climb while the marker is on screen, then fall back toward zero the moment you walk away.

Keep reading the full lesson

Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.

Still ahead in this lesson
  • How it works
  • If something went wrong
  • What you can do now
  • Try it yourself

The remainder of Measure performance with resmon and the profiler is available to FiveM School members.