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: refactor imbuement decay to per-item management #3134

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

Conversation

dudantas
Copy link
Contributor

@dudantas dudantas commented Nov 20, 2024

Description

This refactors the imbuement decay system, changing it from a player-wide loop to a per-item approach. This significantly optimizes performance by reducing redundant checks and focusing only on items that require decay updates. The refactor includes:

  • Dynamic scheduling based on active imbuements.
  • Handling decay conditions for protection zones, fight mode, and backpack rules directly on individual items.
  • Improved scalability and maintainability of the code.

Resolves #3135

Behaviour

Actual

The previous implementation iterated through all players and their inventory items to process imbuement decay. This led to unnecessary overhead, even for players with no relevant items.

Expected

The new implementation tracks only items with active imbuements, dynamically managing their decay schedule and conditions. This minimizes unnecessary processing and ensures accurate decay handling.

Type of change

  • Performance improvement (non-breaking change that improves efficiency)
  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested

The changes were tested with the following scenarios:

  • Test A: Items with imbuements were observed for accurate decay, ensuring decay stops or continues correctly based on conditions.
  • Test B: Players in protection zones and fight mode were tested to ensure appropriate imbuement handling.

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
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Refactored the imbuement decay system to manage individual items directly instead of iterating through all players. This improves performance by:

Tracking only items with active imbuements.
Scheduling events dynamically based on items needing updates.
Reducing redundant checks and player-wide loops.
Simplifying imbuement decay logic while preserving existing functionality, including protection zone, fight mode, and backpack-specific rules.
This change optimizes the handling of imbuements and ensures better scalability.
@dudantas dudantas force-pushed the dudantas/perf-check-imbuements branch from 14deabf to c001339 Compare November 20, 2024 02:58
Copy link

sonarcloud bot commented Nov 20, 2024

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.

Performance: rework in Game::checkImbuements
1 participant