Skip to content

perf(client): reduce unnecessary frame polling in weapon loops#219

Open
Lens931 wants to merge 2 commits into
qbcore-framework:mainfrom
Lens931:perf/reduce-client-frame-polling
Open

perf(client): reduce unnecessary frame polling in weapon loops#219
Lens931 wants to merge 2 commits into
qbcore-framework:mainfrom
Lens931:perf/reduce-client-frame-polling

Conversation

@Lens931

@Lens931 Lens931 commented Jun 15, 2026

Copy link
Copy Markdown

Summary

This PR reduces unnecessary client-side frame polling in qb-weapons.

The current client logic contains multiple while true loops using Wait(0). Some of these checks only need to run every frame during active weapon states, such as firing, drawing, holstering, or interacting with weapon repair points.

This patch keeps weapon behavior responsive while reducing idle client CPU usage.

Problem

On FiveM, Wait(0) runs every frame. With multiple always-running client loops, this can create unnecessary resource usage even when the player is idle, unarmed, or not interacting with weapons.

This is not described as a memory leak. It is more accurately a client-side performance issue caused by legacy per-frame polling.

Changes

  • Reduced unnecessary Wait(0) usage in client weapon loops.
  • Added more dynamic waits depending on player state.
  • Kept frequent checks only when weapon input or weapon state requires it.
  • Optimized weapon draw / holster polling.
  • Preserved existing behavior for shooting, reload, ammo sync, weapon quality, throwable weapons, and repair points.

Expected result

  • Lower idle client usage in resmon.
  • Less unnecessary polling.
  • No visible behavior change for players.
  • Better scalability for larger QBCore servers.

Test checklist

Tested or should be tested:

  • Idle unarmed player
  • Armed player not shooting
  • Semi-auto shooting
  • Automatic shooting
  • Reloading
  • Weapon quality degradation
  • Weapon repair point interaction
  • Throwable weapons
  • Snowballs
  • Weapon draw animation
  • Weapon holster animation
  • Direct weapon switching

Lens931 added 2 commits June 15, 2026 20:48
Refactor weapon handling to improve event-based tracking and remove unnecessary loops. Update conditions for setting current weapon and handling broken weapons.
perf(client): optimize weapon draw loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant