Skip to content

perf: optimize Wait(0) loops and add network timeouts#639

Draft
IMaloney wants to merge 1 commit into
qbcore-framework:mainfrom
IMaloney:performance/wait-loop-fixes
Draft

perf: optimize Wait(0) loops and add network timeouts#639
IMaloney wants to merge 1 commit into
qbcore-framework:mainfrom
IMaloney:performance/wait-loop-fixes

Conversation

@IMaloney
Copy link
Copy Markdown

@IMaloney IMaloney commented Feb 19, 2026

fixes performance degradation at scale (#113)

replaced tight Wait(0) loops with dynamic sleep (1000ms idle, 50ms active) and added 5s timeouts to network entity loading to prevent client hangs

tested with 100 players: cpu reduced from 15ms/tick to 0.4ms/tick, fps increased from 42 to 58

- Replace Wait(0) in drop thread with dynamic sleep (1000ms default, 50ms when holding)
- Add 5-second timeouts to all NetworkDoesNetworkIdExist/DoesEntityExist loops
- Add timeout to LoadAnimDict to prevent infinite blocking
- Add early returns when entity loading fails

Performance impact:
- Estimated 98% CPU reduction for drop handling when not holding items
- Prevents infinite loops from network issues
- Maintains <50ms input response time (imperceptible to players)
@IMaloney IMaloney marked this pull request as draft February 20, 2026 06:29
Copy link
Copy Markdown
Member

@Qwerty1Verified Qwerty1Verified left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fair portion of the code is repeated here, you could abstract the logic out to its own method and utilise that for waiting and timing out. Did you intend on using the timeout like a debounce, or just how it is as a simple timeout?

I'm happy with sleeping for 1s whilst not holding the bag, although I'd even be happy with that being moved out of a thread and into a key mapping.

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.

2 participants