Skip to content

perf(nui): reuse thread-local window snapshot in ForAllWindows - #4232

Open
wall3rsyt wants to merge 1 commit into
citizenfx:masterfrom
wall3rsyt:perf/nui-window-snapshot-reuse
Open

wall3rsyt wants to merge 1 commit into
citizenfx:masterfrom
wall3rsyt:perf/nui-window-snapshot-reuse

Conversation

@wall3rsyt

Copy link
Copy Markdown

What

  • Make the ForAllWindows snapshot vector thread_local and fill it with assign() instead of copy-constructing a new vector every frame.

Why / impact

ForAllWindows copies the window list each frame so callbacks run outside the manager lock (avoiding deadlocks with window creation/destruction). The copy currently heap-allocates a fresh vector every call. Making the vector thread_local lets successive frames reuse its capacity, removing a per-frame allocation from the render hot path.

Trade-offs

None. The snapshot is cleared and reassigned each call; thread_local storage is destroyed at thread exit.

Testing

Compiled and linked nui-core in a local Debug x64 client build. Not runtime-tested in-game.

ForAllWindows copies the window list every frame so callbacks run
outside the manager lock. Make the snapshot vector thread_local and
use assign() to reuse its capacity across frames, avoiding a heap
allocation on every render tick.

Signed-off-by: wall3rsyt <[email protected]>
@github-actions github-actions Bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid Requires changes before it's considered valid and can be (re)triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant