Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: skip spectator iteration if container has holding player #3421

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dudantas
Copy link
Member

@dudantas dudantas commented Mar 6, 2025

Description

Optimized onUpdateContainerItem and onRemoveContainerItem to avoid iterating over spectators when the container has a holding player. If a holding player is present, updates are sent directly to them, preventing unnecessary performance overhead. This change reduces unnecessary iterations and improves efficiency when handling item updates inside player containers.

Behaviour

Actual

Every container item update/removal iterates over all nearby spectators, even when the item belongs to a holding player.

Expected

When a holding player exists, only they receive the update, skipping the expensive spectator iteration.

Type of change

  • Performance improvement (optimization without changing behavior)

How Has This Been Tested

Validated through gameplay testing and logging to ensure item updates are properly handled without iterating spectators when a holding player exists.

  • Verified container updates work correctly when a holding player is present with visual studio profiling.
  • Ensured spectator updates still occur when needed

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

dudantas added 2 commits March 6, 2025 16:27
Added a check in onUpdateContainerItem and onRemoveContainerItem to see if the container has a holding player. If so, it sends updates only to that player and skips iterating over spectators altogether. This avoids unnecessary scanning of spectators and reduces overhead when the item is already with a single, known holder.
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.

3 participants