A lagging server kills communities faster than anything else. If players are falling through the map, cars are teleporting, or inventory menus take 5 seconds to open, they will leave.
Optimization is an ongoing process. This guide covers how to diagnose and fix the most common performance issues in FiveM.
Understanding Server vs Client Lag
The biggest mistake server owners make is confusing server lag with client lag. They require entirely different solutions.
Server-Side Lag (Desync)
Symptoms:
- Players teleporting while driving.
- Chat messages taking seconds to appear.
- Database actions (buying a car, dropping an item) timing out or failing.
Causes:
- The VPS CPU is overloaded (100% usage).
- A server script is stuck in an infinite loop.
- Slow database queries lacking proper indexes.
Client-Side Lag (Low FPS)
Symptoms:
- Players experiencing low FPS (e.g., dropping from 60 to 20 FPS).
- Texture loss (buildings invisible, roads turning blurry, falling through the floor).
- UI stuttering.
Causes:
- Streaming too many high-poly custom cars in one area.
- Massive, unoptimized MLOs (custom interiors).
- Client scripts drawing too many 3D texts or markers every frame.
Fixing Client Lag: The Resource Monitor
To fix low FPS, you need to identify which script is eating up CPU time on the player's computer.
- Join your server.
- Press
F8to open the console. - Type
resmon 1and hit Enter.
A window will appear showing all running resources. Look specifically at the CPU msec and Time % columns.
- A highly optimized script should run at 0.00ms to 0.01ms.
- If a script is constantly running above 0.50ms, it is poorly optimized.
- If a script hits 1.0ms+, it needs to be disabled or completely rewritten immediately.
Common Culprits: Scripts that use Citizen.Wait(0) loops to check distances for drawing 3D text. These loops should be optimized to Citizen.Wait(1000) when the player is far away, and only drop to 0 when the player is within a few meters.
Fixing Texture Loss (Streaming Budgets)
FiveM has strict memory limits for streaming custom assets to prevent crashes.
If your players are losing textures in the city center, your streaming budget is exhausted.
How to Fix It:
- Compress Your Cars: Use OpenIV to check the
.ytd(texture dictionary) files of your custom cars. No single.ytdfile should ever exceed 16MB. If it does, you must resize the textures inside it (e.g., from 4K down to 2K or 1K) using a photo editor and re-import them. - Remove Unused Assets: Don't keep 50 custom police cars if only 5 are actively used.
- Optimize MLOs: Some poorly made MLOs have thousands of unnecessary polygons. Remove them if they cause issues.
Fixing Server Lag: Hardware and Database
If your resource monitor looks clean but players are still desyncing, the issue is on your host machine.
1. Upgrade Your VPS Hardware
FiveM's FXServer is primarily single-threaded. This means having 32 slow CPU cores is completely useless. You need fewer cores with very high clock speeds. Stockhosting specifically utilizes processors like the AMD Ryzen 9 9950X, which boasts massive single-core performance, to prevent server thread hitches.
2. Database Optimization
If your database is slow, your framework (QBCore/ESX) will choke.
- Ensure you are using NVMe SSDs for your database.
- Keep your
oxmysqlormysql-asyncresource updated to the absolute latest version. - Regularly clear old data (like dead characters, empty inventories, or abandoned vehicles) from your SQL tables.
Conclusion
Optimization requires vigilance. Never add 20 new scripts at once without checking the resmon impact of each one. Keep your textures small, your loops efficient, and your hardware powerful.
