Tebex

FiveM Performance: Stop Blaming the Framework

Before blaming your FiveM framework for poor performance, take a closer look at your resources, database queries and server architecture. Learn what actually causes lag, how to identify bottlenecks and how to build a faster, more stable server.

  • 12 min read
  • 12 views

FiveM Performance: Stop Blaming the Framework

The biggest misconception in FiveM development is that your server is slow because you picked the wrong framework.

People switch from ESX to QBCore, from QBCore to QBOX, replace half their resources and expect their server to magically start running at 0.00ms.

Sometimes it helps. Most of the time, the real problem is still there.

Performance is rarely about the framework alone. It is about how your resources behave, how often they execute code, how they communicate with the database and how much unnecessary work they do.

If you are building a FiveM server, understanding this early will save you hours of debugging and potentially hundreds of unnecessary resource replacements.

This guide focuses on the things that actually matter when optimizing a FiveM server, especially when working with Lua, QBOX and the ox ecosystem.

What performance actually means in FiveM

When people talk about server performance, they often mix several different problems together.

There are at least three areas worth understanding: - Client performance: FPS drops, stuttering, high resource usage and slow UI rendering. - Server performance: Resource execution time, server thread load, synchronization and delayed events. - Database performance: Slow queries, excessive database calls, missing indexes and unnecessary data retrieval.

These problems can overlap, but they are not the same thing.

A resource showing 0.20ms in resmon is not automatically responsible for server-wide lag. Likewise, a server with low resource execution times can still suffer from database bottlenecks or client-side performance issues.

The first rule is simple: identify what is actually slow before changing anything.

The biggest performance killers

Most performance problems do not come from one massive mistake. They come from dozens of small decisions that nobody questions.

Here are the areas I would investigate first.

1. Unnecessary loops

This is probably one of the most common mistakes in FiveM Lua development.

A lot of resources rely on permanent threads:

CreateThread(function() while true do Wait(0) -- Check player position -- Check vehicle state -- Check job -- Check nearby entities -- Update something end end)

There is nothing inherently wrong with Wait(0). Some things genuinely need to execute every frame, such as drawing 3D text or handling certain controls.

The problem starts when developers use it for things that only need to happen every 250, 500 or even 1000 milliseconds.

Think about a resource checking whether a player is near a shop. Does it really need to check that 60 times per second?

Usually not.

A better approach is to separate detection from rendering:

local nearShop = false CreateThread(function() while true do local playerCoords = GetEntityCoords(PlayerPedId()) nearShop = #(playerCoords - shopCoords) < 10.0 Wait(500) end end)

Now you only perform the expensive proximity check twice per second.

If you need to draw something every frame, use a separate lightweight thread that only runs while the player is nearby.

The rule is simple: don't execute code more often than the feature requires.

2. Database queries

Your database can become one of the biggest bottlenecks on a growing server.

Think about a typical roleplay server: - Player inventory - Character information - Businesses - Garages - Vehicle ownership - Housing - Banking - Invoices - Crafting - Logs and statistics

Every one of these systems can communicate with MySQL.

Now imagine 100 players using these systems simultaneously.

The problem is not necessarily the number of queries. It is how they are written, when they execute and how much data they retrieve.

Some common mistakes: - Fetching an entire table when you only need one record. - Running the same query multiple times during one interaction. - Saving unchanged player data repeatedly. - Missing indexes on frequently searched columns. - Loading data that could have been cached. - Performing unnecessary database operations inside frequently executed loops.

For example, instead of repeatedly retrieving a player's business information from the database every time they open a menu, you can cache frequently accessed data and update it when something actually changes.

Another important detail: use parameterized queries.

local result = MySQL.single.await( 'SELECT * FROM businesses WHERE id = ?', { businessId } )

This is cleaner and safer than building SQL queries through string concatenation.

With oxmysql, asynchronous operations and awaited operations both have their place. Just remember that awaiting a query still means your code depends on that database operation finishing before it continues.

A database query should have a reason to exist. Not just because it was convenient to write one.

3. Too many resources doing the same thing

This is where things get particularly messy on established servers.

You install one inventory, then another resource brings its own inventory logic. You add a targeting system, but an older script still uses its own interaction zones. You install a notification system, but half your resources continue using the default framework notifications.

Suddenly, you have multiple systems trying to solve the same problem.

On a QBOX server, I would establish a consistent stack from the beginning:

| Responsibility | Recommended solution | |---|---| | Core framework | qbx_core | | Inventory | ox_inventory | | Targeting | ox_target | | Shared utilities | ox_lib | | Database | oxmysql |

This does not mean every resource must use exactly the same implementation. It means you should have one agreed way of handling common functionality.

If you are writing custom scripts, build around these existing systems instead of reinventing them every time.

For example, there is little reason to create another targeting system when ox_target already provides the functionality you need.

4. Client-side asset overload

Not every performance issue is caused by Lua.

This is particularly important on servers with large custom content packs.

MLOs, vehicles, clothing, textures, props and other streamed assets can have a significant impact on players' computers.

You might have perfectly optimized scripts and still receive complaints about: - Low FPS in specific locations. - Textures taking too long to load. - Missing or invisible objects. - Long loading times. - Stuttering when entering certain areas.

A common mistake is assuming that a resource with low script execution time is automatically lightweight.

It is not.

A resource can consume very little CPU while delivering enormous amounts of assets to the client.

Pay attention to texture sizes, model complexity, collision files and unnecessary duplicated assets.

Also, do not keep multiple versions of the same asset pack running just because you are afraid to remove something.

5. Event spam and unnecessary synchronization

FiveM is built around events, but that does not mean you should send everything through them.

Imagine a resource sending player coordinates, vehicle information or inventory data to the server every few milliseconds.

Now multiply that by the number of players online.

You are creating network traffic, server-side work and additional processing for information that might not even be needed.

A better approach is to send data when something actually changes.

For example: - Player enters a business zone. - Player starts crafting. - Player purchases an item. - Vehicle changes ownership. - Player completes a delivery.

These are meaningful events.

You do not need to constantly tell the server something that has not changed.

There is also an important security consideration here: never trust client-side events with sensitive operations.

A client can request an action, but the server should validate whether that action is actually allowed.

Check ownership, permissions, distance, item requirements and payment server-side.

Performance and security often benefit from the same architectural decision: send less unnecessary data and validate meaningful actions centrally.

How to actually find the problem

You cannot optimize something you have not measured.

And this is where many developers waste their time.

They see a player complaining about lag, open the resource folder and start randomly changing scripts.

Don't do that.

FiveM already provides tools that can help you identify what is happening.

Resmon

resmon is the first tool worth learning.

Open your F8 console and type:

text resmon true

It shows resource execution time and memory usage on your client.

Use it to identify resources that consume too much processing time, especially when players experience FPS drops.

However, there is an important distinction:

**Resmon is not a measurement of your entire FXServer's CPU usage.**

It monitors resources running on your client. If your server console reports a server thread hitch, you need to investigate server-side execution instead.

The FiveM Profiler

This is one of the most useful tools available when you need to find the exact source of a performance problem.

In the relevant console, run:

text profiler record 500

Wait for the recording to finish, then:

text profiler view

The profiler lets you inspect execution timelines and identify expensive threads, functions and parts of your code.

You can use it both client-side and server-side.

For example, if your server regularly reports:

text server thread hitch warning

You can record a server profile during the problematic activity and investigate which resource is responsible.

Instead of guessing that your inventory is broken, you can inspect the actual execution timeline and narrow the problem down.

That is a much better way to approach optimization.

Test under real conditions

An empty development server tells you very little about how your server will behave with 100 players.

Some scripts are perfectly fine with five players but become expensive when they start processing every player, vehicle or entity.

Test scenarios that actually represent your server: - 50+ players online. - Multiple businesses operating simultaneously. - Several players using inventory and crafting. - Police chases with multiple vehicles. - Robberies with NPCs and synchronized entities. - Players entering and leaving heavily populated areas.

Measure before and after every significant change.

If you change five things at once, you will have no idea which change actually helped.

Common optimization mistakes

Sometimes developers make performance worse while trying to improve it.

Here are a few things I would avoid.

1. Adding Wait(1000) everywhere

Increasing wait times can reduce how often a thread executes, but it does not automatically make the resource better.

If a script needs to react immediately to a player interaction, introducing a one-second delay might make the feature feel broken.

Optimize the actual workload instead of blindly increasing delays.

2. Rewriting everything in another language

Lua is not automatically the problem.

Moving a poorly designed resource to JavaScript or C# will not magically fix its architecture.

The same unnecessary loops, excessive database calls and inefficient logic can exist in any language.

Choose a language based on the requirements of your project, not because someone claims it is inherently faster.

3. Removing resources without understanding dependencies

This happens more often than it should.

You notice a resource consuming processing time, stop it and suddenly three other systems stop working.

Before removing anything, understand what depends on it.

A framework resource might appear expensive because other resources are constantly calling its exports or events.

Fix the source of unnecessary work rather than removing something that other systems rely on.

4. Optimizing code that is not causing problems

Not every resource needs to be rewritten.

If a script performs well, has no measurable bottlenecks and behaves correctly under realistic conditions, leave it alone.

Your time is better spent fixing the resources that actually cause problems.

What I would do differently when starting a new server

After working with different FiveM systems and building custom resources, I would approach a new project differently from day one.

My priorities would be:

1\. **Establish a consistent framework and ecosystem. For example, QBOX with ox_lib, ox_inventory, ox_target and oxmysql. 2\. Build reusable systems. Notifications, callbacks, permissions, logging and shared utilities should not be reinvented in every resource. 3\. Keep resources independent. A business script should not need to know the internal implementation of your entire inventory system. 4\. Use events instead of constant polling. React to changes whenever possible. 5\. Keep database operations predictable. Cache frequently accessed information and save data when necessary. 6\. Profile every major system. Especially resources that handle many players, entities or database operations. 7\. Test before releasing.** A script working perfectly for its developer does not mean it is ready for a populated server.

One more thing: document your dependencies.

When you have 50, 100 or even 200 resources, remembering which resource depends on which export becomes increasingly difficult.

A simple dependency list can save you hours when debugging a broken server.

So, what actually makes a FiveM server performant?

There is no magic framework, resource or configuration that will solve every performance problem.

A good framework gives you a solid foundation. A good collection of resources gives you functionality. But neither guarantees that everything will run smoothly.

The biggest difference comes from how the entire server is designed. - Avoid unnecessary execution. - Keep database operations under control. - Do not duplicate existing systems. - Synchronize only what needs to be synchronized. - Keep custom assets reasonable. - Measure actual performance instead of guessing.

And most importantly, do not confuse a high resource count with a poorly optimized server. Having 150 resources is not automatically worse than having 50. What matters is what those resources actually do.

A well-optimized FiveM server is not the one with the fewest > resources. It is the one that does the least unnecessary work while > delivering everything players expect.

Final thoughts

If there is one thing I would recommend to anyone starting FiveM development, it is to learn performance profiling early.

Do not wait until players start complaining about FPS drops or your server begins throwing hitch warnings.

Build good habits from the beginning. Write code that has a clear purpose, understand the systems you depend on and test everything under realistic conditions.

You will eventually reach a point where adding another feature is easy. Making sure that feature does not negatively affect everything else is the real challenge.

And that is what separates simply writing FiveM scripts from actually engineering a FiveM server.

------------------------------------------------------------------------

References: - Cfx.re - Performance and Hitch Warnings - Cfx.re - Using the Profiler - Cfx.re - Console Commands

  • FiveM performance
  • FiveM optimization
  • FiveM server optimization
  • FiveM scripting
  • FiveM Lua
  • QBOX optimization
  • QBCore performance
  • ESX performance
  • oxmysql
  • ox_lib
  • resmon
  • FiveM profiler
  • FiveM server lag
  • FiveM resources
  • Lua optimization
All posts

More from the blog