Engineering
Using the FiveM profiler to find slow code
How to use FiveM’s built-in profiler on the client and server: profiler record, status, view and saveJSON, opening profiles in Chrome DevTools, reading frame time and resource threads, and turning a spike into a fix.
Overview
resmon tells you which resource is slow; the profiler tells you why. It records every frame for a few seconds, then shows exactly which resource, which thread and which line took the time — on the client or on the server. It is the tool that ends arguments about which script causes “server lag”.
01Recording a profile
- Wait until the lag is happening (or reproduce it).
- Server: type
profiler record 500in the server console. Client: open F8 and type the same. - Check
profiler statusuntil the capture completes. - Run
profiler viewto open it in Chrome — on the server, copy the link it prints into Chrome. - Or save it with
profiler saveJSON lag-2026-09-11.jsonto study later or share with a developer.
Reading the result
The profile opens in Chrome DevTools’ Performance view. Frame time is shown per frame; tall frames are hitches. Zoom into one, then hover the coloured blocks beneath it: each shows the resource and the file and line it was running, with its duration in milliseconds.
- One block that is always wide → a heavy function that runs every frame.
- Occasional huge blocks → a database callback, a big loop or a large event payload.
- Many small blocks from one resource → too many threads or per-frame loops.
Server hitches
When the server console prints “server thread hitch warning”, the main server thread took too long for a tick. Profiling the server during those moments shows which resource blocked it — usually synchronous work in an event handler, a huge loop over players or a slow query waited on in the wrong place. The minimap studio’s server performance guide covers the server side in more depth.
Turning a finding into a fix
| Profile shows | Typical fix |
|---|---|
| A per-frame loop doing distance checks | Adaptive sleep — threads and Wait |
| Repeated native calls in one function | Cache results in locals — Lua performance |
| A database wait in a hot path | Cache or batch queries — oxmysql |
| A huge event payload | Send less, or use latent events — events |
Frequently asked questions
How do I use the FiveM profiler?
Run profiler record 500 in the server console or F8, wait for profiler status to finish, then profiler view to open it in Chrome.
Where does profiler saveJSON save the file?
In the folder containing your server’s run script.
How do I open a saved profile?
In Chrome DevTools, open the Performance tab, right-click and load the profile JSON.
Should I use resmon or the profiler?
resmon to find which resource is slow; the profiler to see which function inside it and why.
Need this built, not just explained?
Ten years of FiveM work, from Lua to NUI
Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.
Related guides
- Engineeringresmon: finding the resource that is eating your framesPress F8 and type resmon 1 (or resmon true) to open the client resource monitor. The CPU msec column is how many milliseconds per frame each resource uses; idle resources should sit near 0.00–0.02 ms, and anything consistently above about 0.5 ms deserves a look. Sort by CPU, reproduce the situation where it lags, and inspect the worst resource’s loops.
- EngineeringThreads and Wait in FiveM: loops that do not eat framesCreateThread(fn) starts a coroutine that runs alongside the game; Wait(ms) pauses it and lets everything else run. Wait(0) resumes on the next frame, so the loop runs every frame (60+ times a second). Use it only while you must draw or read input every frame; otherwise sleep for hundreds of milliseconds, and make loops adaptive — fast when the player is near something, slow when they are not.
- EngineeringFiveM server optimizationRead resmon properly, kill per-frame loops, tune OneSync and entity limits, and find the database query that is freezing your server.