Selt 4fc2d72941 perf(es_extended/client): only look up the closest player when the pickup prompt is used
The pickup loop calls ESX.Game.GetClosestPlayer at the top of every iteration, but
closestDistance is only read inside the nested check that runs when the player presses
the pickup control right next to a drop. As soon as any pickup is within five metres
the loop sets Sleep to 0, so the lookup runs every frame while standing near a drop.

GetClosestPlayer builds two tables and calls GetPlayers plus GetPlayerPed,
DoesEntityExist and GetEntityCoords per player, so the cost grows with the number of
players in scope - worst exactly when the server is busy.

Measured in game on artifact 25770 with a single player standing on a dropped pickup,
reading es_extended in the resource monitor over about 20 seconds each:

  before: 0.16 - 0.18 ms, sitting around 0.17
  after:  0.13 - 0.15 ms, sitting around 0.14

The two ranges do not overlap. Idle, with no pickup within five metres, is 0.04 ms in
both cases, as expected, since the loop sleeps 1500 ms then.

One player is the smallest saving this can ever show, because GetClosestPlayer scales
with the number of players in scope. The larger saving on a populated server follows
from that per player work and was not measured, testing it would need several clients.

Behaviour is unchanged, the value is computed in the same frame it is used.
2026-07-27 17:33:11 +02:00
2025-07-28 11:38:03 +02:00
2025-10-01 22:16:13 -05:00
2026-05-25 12:12:51 +02:00

ESX Legacy

Discord - Website - Documentation

Want more resources? You can browse the Cfx.re Releases board for more!

ESX is the leading framework, trusted by over 12,000 communities to provide the highest quality roleplay servers on FiveM


💗 Supporters

Interested in helping us? Take a look at our patreon

We would like to sincerely thank the following donors who helped fund the development of ESX.
Mohamad Buhamad - Michael Hein - RoadToSix - Montree Narathong
Saydoon - Muhannad alyamani - iSentrie - Wecity - Samuel Nicol
Kyle McShea - Artin - Mathias Christoffersen - Jaylan Yilmaz - Callum
CONGRESS KW - Michael Hein - Smery sitbon - daZepelin - CMF Community

S
Description
Official Repo For core resources for esx-legacy
Readme 49 MiB
Languages
JavaScript 62.3%
Lua 34.8%
TypeScript 1.2%
HTML 0.8%
CSS 0.7%
Other 0.2%