Fix hitching every 300 units when many objects are around - #5307
Fix hitching every 300 units when many objects are around#5307Flashmyname wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 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::RemoveElementsto remove sector elements from the active list via onelist::remove_ifpass instead oflist::removeper 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.
a53a2bc to
f396514
Compare
There was a problem hiding this comment.
🟢 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
f396514 to
59b6fa4
Compare
There was a problem hiding this comment.
🟢 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
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
OnEnterSectordeactivates a sector,RemoveElementscalledlist::removeonce 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_ifpass instead: k + n.CClientStreamer::OnElementEnterSectoris 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
AddElementsO(1), butRemoveElementskept callinglist::removeper 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
fpslimit0, vsync off, three sessions per build.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