Skip to content

Conversation

@jprzimba
Copy link
Collaborator

Tracker Functions Optimization

Batching has been implemented for tracker functions to reduce I/O and allocations:

Changes Implemented:

  1. Batching Data Structure:
  • BatchedTrackerData to accumulate loot, supply, impact, and input data
  • Control flags to avoid multiple schedules
  1. Optimized Functions:
  • sendLootStats: Accumulates items and values, schedules flush in 250ms
  • updateSupplyTracker: Accumulates items and values, schedules flush in 250ms
  • updateImpactTracker: Accumulates combat data, schedules flush in 250ms
  • updateInputAnalyzer: Accumulates input data, schedules flush in 250ms
  1. Flush Function:
  • flushBatchedTrackerData: Sends aggregated data and clears the buffer
  • Sends aggregated metrics (reduces I/O)
  • Sends individual data to client/party (keeps functionality)

Benefits:

  • I/O Reduction: Metrics sent in batches instead of per event
  • Fewer Allocations: Data accumulated in reusable structures
  • Coalescence: Multiple events in the same tick are processed together
  • Controlled Latency: Flush in 250ms maintains responsiveness

Impact:

  • Significantly reduces I/O overhead in high-activity situations (intense combat, mass loot)
  • Keeps original functionality intact
  • Improves overall server performance under load

@jprzimba jprzimba added the enhancement New feature or request label Oct 14, 2025
@jprzimba jprzimba changed the title fix: batched trackers updated improve: batched trackers updated Oct 14, 2025
self->flushBatchedTrackerData();
},
"Player::flushBatchedTrackerData"
);

Choose a reason for hiding this comment

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

if you sum the amount, it'll create a bug with the "max-dps" and "all-time high"
But if you don’t sum it, you’ll send all of them separately so it’ll be the same, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, sending impact events separately is the right behavior, and it’s what the code already does.


// Send aggregated loot stats
if (batchedTrackerData.lootValue > 0) {
g_metrics().addCounter("player_loot", batchedTrackerData.lootValue, { { "player", getName() } });

Choose a reason for hiding this comment

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

duplicated info in g_metrics()
g_metrics().addCounter("player_loot", value, { { "player", getName() } });

- Previous behavior: flushBatchedTrackerData emitted a single aggregated counter using batchedTrackerData.lootValue ( src/creatures/players/player.cpp:1756 ).
- Change: Emit one counter per loot item using its computed value (coins or “Lootmonger” sell price) during the loop over lootItems . Removed the aggregated emission.
- Result: Metrics reflect each loot event individually and avoid double-reporting caused by batch aggregation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants