Skip to content

Conversation

@Arufonsu
Copy link
Contributor

@Arufonsu Arufonsu commented Feb 1, 2026

performance: optimize packet broadcasting by caching entity snapshots

  • Add snapshot caching for entity stats, vitals, statuses and player equipment
  • Cache per-(player,npc) aggression to skip unchanged NpcAggressionPacket sends
  • Cache per-(player,map) visible map-items hash to avoid regenerating identical MapItemsPacket data
  • Skip redundant broadcasts when cached state matches current values
  • Clear all snapshots when entities leave map/layer/instance (including player/npc aggression)
  • Batch vital and status updates to only include entities with actual changes
  • Equipment broadcasts now only send when items change

These changes significantly reduce network bandwidth and server CPU in high-entity scenarios (raids, events, crowded maps) by eliminating unnecessary/duplicate packet transmissions to clients while preserving first-send guarantees and correctness. Behavior is fully backwards-compatible; clients see the same game state with less packet noise and lower latency impact from server-side broadcasting.

@Arufonsu Arufonsu requested a review from a team February 1, 2026 17:45
@Arufonsu Arufonsu added the performance Performance optimization label Feb 1, 2026
@Arufonsu Arufonsu marked this pull request as draft February 1, 2026 19:54
@Arufonsu Arufonsu force-pushed the performance/entity-packets-broadcast branch from 80b30e8 to 060e558 Compare February 1, 2026 22:58
- Add snapshot caching for entity stats, vitals, statuses and player equipment
- Cache per-(player,npc) aggression to skip unchanged NpcAggressionPacket sends
- Cache per-(player,map) visible map-items hash to avoid regenerating identical MapItemsPacket data
- Skip redundant broadcasts when cached state matches current values
- Clear all snapshots when entities leave map/layer/instance (including player/npc aggression)
- Batch vital and status updates to only include entities with actual changes
- Equipment broadcasts now only send when items change

These changes significantly reduce network bandwidth and server CPU in high-entity scenarios (raids, events, crowded maps) by eliminating unnecessary/duplicate packet transmissions to clients while preserving first-send guarantees and correctness. Behavior is fully backwards-compatible; clients see the same game state with less packet noise and lower latency impact from server-side broadcasting.
@Arufonsu Arufonsu force-pushed the performance/entity-packets-broadcast branch from 060e558 to 3a2d944 Compare February 1, 2026 22:59
@Arufonsu Arufonsu marked this pull request as ready for review February 1, 2026 23:00
Copy link
Member

@pandinocoder pandinocoder left a comment

Choose a reason for hiding this comment

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

How does the cache interact with clients connecting after the cache is established? Does the cache get hit there and skip sending values to them?

Does the cache properly clear when NPCs and players die/spawn/connect/disconnect?

Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com>
Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com>
@Arufonsu
Copy link
Contributor Author

Arufonsu commented Feb 3, 2026

How does the cache interact with clients connecting after the cache is established? Does the cache get hit there and skip sending values to them?

Does the cache properly clear when NPCs and players die/spawn/connect/disconnect?

When clients connect:

  • SendMap → GenerateMapEntitiesPacket creates new EntityPacket objects for all visible entities
  • SendEntityDataTo(player, entity) sends direct uncached packets to the specific connecting player
  • The snapshot caching only affects proximity broadcasts (equipment, stats, vitals, aggression)
  • New players always get the full initial state, then subsequent updates use caching

The cache is cleared via:

  • Death: All entity types (Player, Npc, Resource) call SendEntityDie(entity) which includes ClearEntitySnapshotCache(en)
  • Map transitions: SendEntityLeaveMap, SendEntityLeave, SendEntityLeaveLayer, SendEntityLeaveInstanceOfMap all clear the cache
  • ClearNpcAggressionSnapshot: Both NPC death and player disconnect (entity leave) remove their aggression cache

@Arufonsu Arufonsu requested a review from a team February 3, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants