# ⚡ Performance Optimization

Start with a reproducible symptom, not a list of configuration tweaks. Record what players were doing, which resources were active, and whether the problem affected one client or the whole server.

## Performance Overview

| Symptom | First investigation | Avoid assuming |
| --- | --- | --- |
| One player's frame rate drops | Client resource costs, rendering, and the location or interface involved | That the server needs more RAM |
| Several players experience a server hitch | A server-side profile captured during the hitch | That every installed script is equally responsible |
| A purchase or save takes too long | The request path, database queries, and external calls involved | That a database setting alone is the cause |
| Players disconnect or have high latency | Connection logs and the affected network path | That script CPU time explains every connection problem |

## Quick Performance Checklist

Save the FXServer build, resource revisions, relevant configuration, and steps that reproduce the issue. Keep the baseline capture. Make one change on a test server, repeat the workload, and compare the same measurements. Record regressions as well as improvements.

Do not remove an apparently idle resource without checking which other resources depend on it.

## Performance Monitoring

### Built-in FiveM Tools

The [Cfx.re profiler guide](https://docs.fivem.net/docs/scripting-manual/debugging/using-profiler/) documents profiling on both the server and client. Run the following in the **server console** to investigate server work, or the **client F8 console** to investigate that client:

```text
profiler record 500
profiler status
```

After the capture has finished, save it:

```text
profiler saveJSON qbcore-before.json
```

The frame count is a sample capture size, not a performance target. Capture the activity that triggers the problem; an idle capture may miss it. Use the profiler to identify the resource and call path responsible for the expensive work.

For a client-side overview, the [Cfx.re console reference](https://docs.fivem.net/docs/client-manual/console-commands/#resmon) documents:

```text
resmon true
resmon false
```

`resmon` runs in the **client F8 console**, not the server console. It is a developer command; access depends on the client mode. See Cfx.re's [developer-command instructions](https://docs.fivem.net/docs/client-manual/console-commands/#developer-commands) if access is denied. Its readings are not a measurement of total server CPU or memory. See also [Resmon Basics](/docs/performance/resmon-basics).

## Common Performance Bottlenecks

Use the profile to choose where to inspect code. Look for work repeated more often than needed, large event payloads, repeated queries, or state that grows after reconnects and resource restarts. These are investigation leads, not proof of the cause.

For database work, keep the query, parameters with private values removed, execution plan, and observed duration. Compare behavior with representative data rather than adding indexes to every column.

## Hardware Recommendations

There is no single hardware specification or player-count guarantee established by this guide. Size the server from measurements of your actual resource set and workload. A core count, clock speed, or advertised network rate alone does not establish capacity.

Before purchasing an upgrade, identify whether the limiting factor is resource execution, database work, memory pressure, storage, or the network. Save enough information to repeat the test on the proposed setup.

## Performance Optimization Sections

###

### Resource performance

    Investigate loops and resource-level work using profiling results.

### Server optimization

    Review deployment and resource configuration after identifying the symptom.

### Resource debugging

    Trace errors and reproduce failures before changing code.

## Best Practices Summary

Keep a before-and-after capture with the resource revision and test steps. Reject a change that makes the measured number look better by breaking gameplay or skipping required work. Recheck the affected behavior after reconnects, restarts, and a representative period of use.
