Skip to content

Move entity model streaming and polling to worker threads - #5303

Open
iManGaaX wants to merge 5 commits into
multitheftauto:masterfrom
iManGaaX:patch-3
Open

Move entity model streaming and polling to worker threads#5303
iManGaaX wants to merge 5 commits into
multitheftauto:masterfrom
iManGaaX:patch-3

Conversation

@iManGaaX

@iManGaaX iManGaaX commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Refactored CClientModelRequestManager to process model streaming requests asynchronously via worker threads.
  • Implemented a dual-mutex architecture utilizing m_Mutex for container safety and m_ModelInfoMutex to serialize game engine and RenderWare calls.
  • Added a thread-safe cancellation mechanism (bCancelled) ensuring all memory cleanup and engine callbacks remain strictly on the main thread inside DoPulse()

Motivation

  • Eliminates severe frame drops and game stuttering (FPS stutters) caused by synchronous disk I/O and heavy model loading operations on the main thread.

Test plan

  1. Compiled the MTA client source code locally.
  2. Conducted stress tests by rapidly spawning and destroying custom entities and models to simulate heavy streaming loads.
  3. Verified stable frame rates, smooth movement, and complete absence of use-after-free crashes or deadlocks during dynamic request cancellations.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

Added worker thread management for model requests, including start and stop functionality. Enhanced request handling with improved cancellation checks and background processing.
Added atomic flags for background processing and cancellation in SClientModelRequest.
@FileEX FileEX added the refactor label Sep 4, 2026
Reduced worker poll interval for async model loading from 20ms to 5ms. Removed unnecessary cancellation checks in the pulse method.
Removed the cancel queue from the client model request manager.
@iManGaaX iManGaaX closed this Sep 4, 2026
@iManGaaX
iManGaaX deleted the patch-3 branch September 4, 2026 17:58
@iManGaaX
iManGaaX restored the patch-3 branch September 4, 2026 17:58
@iManGaaX

iManGaaX commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Automatically closed because i renamed the branch and forgot that it was associated with this pull request 😑

@iManGaaX iManGaaX reopened this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants