Skip to content

Fix hitching every 300 units when many objects are around - #5307

Open
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/5262-streamer-sector-remove
Open

Fix hitching every 300 units when many objects are around#5307
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/5262-streamer-sector-remove

Conversation

@Flashmyname

@Flashmyname Flashmyname commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Crossing a sector boundary (every 300 units) hitches when there are many objects around, and the hitch grows with their count - even for objects in another dimension. When OnEnterSector deactivates a sector, RemoveElements called list::remove once per element, each walking the whole active list: k x n steps per crossing.

Each element already records the sector it is in, so the active list can be stripped in a single remove_if pass instead: k + n. CClientStreamer::OnElementEnterSector is the only writer of both the sector's element list and that back pointer, and it sets them together, so they cannot disagree. The active-element set is maintained as before.

Motivation

Fixes #5262. This is the half #4695 left behind - it added the active-element set and made AddElements O(1), but RemoveElements kept calling list::remove per element.

Same setup as reported: 8000 x model 1337 along a line, then moving through them.

Test plan

Flying along the reported line (8000 x 1337, x 1000-2600, z 200) at 120 units/s, frame time at each sector boundary (x = 1500, 1800, 2100, 2400) against the same run's empty pass. Server fpslimit 0, vsync off, three sessions per build.

objects in dimension 88 before after
spike at each boundary, over the empty pass +5 to +14 ms 0 to +2 ms
average frame time away from boundaries +0.4 ms +0.4 ms (unchanged, that is #5261)

In the player's own dimension the boundary frames went from 9-13 ms to 5-6 ms; the odd 40-50 ms frame there is GTA loading the models that actually stream in, present before and after.

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.

Copilot AI lite review requested due to automatic review settings September 2, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is small, localized, and preserves existing behavior while addressing the documented performance hotspot.

Pull request overview

This PR optimizes sector deactivation in the client streamer to remove a sector’s active elements in a single pass, reducing the sector-boundary hitch that scaled with nearby object count (including objects in other dimensions), as described in #5262.

Changes:

  • Reworked CClientStreamSector::RemoveElements to remove sector elements from the active list via one list::remove_if pass instead of list::remove per element.
  • Maintains the active-element membership set updates while reducing overall work at sector crossings.

Note for commit message quality (per repo guidelines): include the motivation/goal, a short explanation of the approach/tradeoff (k×n → k+n), and how you tested (the benchmark setup and results table).

File summaries
File Description
Client/mods/deathmatch/logic/CClientStreamSector.cpp Optimizes removal of sector elements from active lists/sets to reduce boundary-crossing hitching.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Client/mods/deathmatch/logic/CClientStreamSector.cpp Outdated
Copilot AI review requested due to automatic review settings September 2, 2026 14:56
@Flashmyname
Flashmyname force-pushed the fix/5262-streamer-sector-remove branch from a53a2bc to f396514 Compare September 2, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is localized and preserves behavior while addressing the reported performance bottleneck; remaining feedback is a minor optimization suggestion.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread Client/mods/deathmatch/logic/CClientStreamSector.cpp Outdated
@Flashmyname
Flashmyname force-pushed the fix/5262-streamer-sector-remove branch from f396514 to 59b6fa4 Compare September 2, 2026 19:10
Copilot AI review requested due to automatic review settings September 2, 2026 19:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is localized, preserves existing streaming bookkeeping behavior, and replaces an objectively inefficient removal pattern with a single-pass approach consistent with the PR’s stated performance goal.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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.

Lag spike every 300 units when moving near alot of objects

2 participants