Skip to content

Optimize Lua timing profiler for #5240 - #5257

Merged
FileEX merged 1 commit into
multitheftauto:masterfrom
MohabCodeX:perf/optimize-lua-timing
Aug 22, 2026
Merged

Optimize Lua timing profiler for #5240#5257
FileEX merged 1 commit into
multitheftauto:masterfrom
MohabCodeX:perf/optimize-lua-timing

Conversation

@MohabCodeX

Copy link
Copy Markdown
Contributor

Summary

Optimizes CClientPerfStatLuaTiming and CPerfStatLuaTiming modules to eliminate CPU throttling and framerate drops caused by UpdateLuaTiming.

This PR is required by and resolves the performance bottleneck identified in #5240, where profiling frequent events under heavy handler load resulted in a 30–40 FPS drop. With these changes, the event system can profile handlers with zero impact during normal gameplay and minimal overhead when stats are polled.

Changes

  • Skips timer queries completely when the profiler is not being viewed, so normal gameplay runs with zero overhead.
  • Accumulates event execution times directly using cached pointers instead of looking up strings and maps on every call.
  • Uses a faster hash map to speed up lookups when stats are requested.
  • Applies the same performance improvements to both client and server modules.

Testing

  • Tested in-game with a resource under 5,000 handlers, confirming the 30–40 FPS drop is completely eliminated while maintaining 100 FPS.

…ating and O(1) direct accumulator

- Replace std::map lookups with CFastHashMap in CClientPerfStatLuaTiming and CPerfStatLuaTiming
- Add direct O(1) UpdateTimingFast accumulator for pre-cached timing blocks
- Implement active profiler gating (IsActive) to bypass expensive clock queries (GetTimeUs) when profiler is inactive
- Synchronize optimizations across both Client and Server performance modules
@FileEX

FileEX commented Aug 22, 2026

Copy link
Copy Markdown
Member

This PR is the result of collaboration as part of #5240. I tested it together with the new event system and I'm getting around 90 FPS with 5K onClientRender handlers, whereas with the old profiler I was seeing FPS drops to around 40–50. The difference is huge.

Since this PR has been tested in a real-world scenario, I believe it's mature enough to be merged. It could also have a positive impact on the current event system, potentially improving player FPS even before the new event system is introduced.

@FileEX FileEX added refactor bugfix Solution to a bug of any kind labels Aug 22, 2026
@FileEX FileEX added this to the 1.7 (Current) milestone Aug 22, 2026
@FileEX
FileEX enabled auto-merge (squash) August 22, 2026 02:33
@FileEX
FileEX merged commit 69b86b6 into multitheftauto:master Aug 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants