Skip to content

Improve performance and code readibility#78

Merged
Nyeriah merged 10 commits intoazerothcore:masterfrom
Nyeriah:perf
Feb 15, 2026
Merged

Improve performance and code readibility#78
Nyeriah merged 10 commits intoazerothcore:masterfrom
Nyeriah:perf

Conversation

@Nyeriah
Copy link
Member

@Nyeriah Nyeriah commented Feb 15, 2026

Module is heavy on per-tick overhead and the code is cluttered with dead debug comments, redundant map lookups, and deep nesting.

MythicmodeInstanceData map bloat

Every read via operator[] silently inserts a default entry for missing keys, growing the map unboundedly:

// Before: inserts false for every instanceId ever queried
bool isMythic = sZoneDifficulty->MythicmodeInstanceData[instanceId];

// After: no insertion on read
bool isMythic = sZoneDifficulty->IsInstanceMythic(instanceId);

Added IsInstanceMythic() helper using find(), replaced all ~12 read-only accesses.

OnAllCreatureUpdate — runs every tick for every creature

  • Moved phase-match check before base health computation (early out before GetCreatureBaseStats/GenerateHealth)
  • Replaced full modifier chain comparison (GetMaxHealth() == scaledHealth computing 3 modifier values) with direct BASE_VALUE comparison
  • Used iterator from CreatureOverrides.find() instead of find-then-bracket double lookup

Double map lookups throughout hot paths

Replaced find() != end() followed by operator[] with single iterator-based access in all damage/heal modifier hooks, OverrideModeMatches, HasCompletedFullTier, SaveMythicmodeInstanceData, GetLowestMatchingPhase, OnPlayerLogin, etc.

// Before: two O(log n) lookups
if (sZoneDifficulty->SpellNerfOverrides.find(spellInfo->Id) != sZoneDifficulty->SpellNerfOverrides.end())
    heal = heal * sZoneDifficulty->SpellNerfOverrides[spellInfo->Id][mapId].NerfPct;

// After: single lookup
auto spellIt = sZoneDifficulty->SpellNerfOverrides.find(spellInfo->Id);
if (spellIt != sZoneDifficulty->SpellNerfOverrides.end()) { ... }

Other fixes

  • VectorContainsUint32 now takes const std::vector<uint32>& instead of by value
  • Cached ShouldNerfInDuels() result where it was called twice in ModifyHealReceived
  • OnInstanceIdRemoved: removed redundant find-before-erase (erase on missing key is a no-op)
  • OverrideModeMatches: rewrote to use find() for both SpellNerfOverrides and MythicmodeInstanceData instead of operator[]

Readability

  • Removed ~30 commented-out LOG_INFO lines and /* debug ... end debug */ blocks
  • Removed empty if (IsDebugInfoEnabled) { /* only comments */ } blocks
  • Reduced nesting in ModifyHealReceived, OnAfterUpdateEncounterState
  • Merged duplicate gossip close handlers
  • Used local references to avoid repeated deep map chains like sZoneDifficulty->NerfInfo[mapId][matchingPhase].SpellDamageBuffPct

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits February 15, 2026 13:32
…helper, fix double lookups, fix operator[] insertions, remove dead code

Co-authored-by: Nyeriah <47818697+Nyeriah@users.noreply.github.com>
…rns in OnAllCreatureUpdate, fix double lookups, remove dead code

Co-authored-by: Nyeriah <47818697+Nyeriah@users.noreply.github.com>
Co-authored-by: Nyeriah <47818697+Nyeriah@users.noreply.github.com>
Co-authored-by: Nyeriah <47818697+Nyeriah@users.noreply.github.com>
…adability

Performance and readability overhaul
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces per-tick overhead and map growth in the zone difficulty module by replacing operator[] reads with find()-based access patterns, flattening control flow, and removing dead debug/comment blocks.

Changes:

  • Added ZoneDifficulty::IsInstanceMythic() and replaced read-only MythicmodeInstanceData[instanceId] access to avoid accidental inserts.
  • Reduced redundant map lookups and nesting in several hot paths (heal/damage modifiers, creature update tick, instance encounter hooks).
  • Cleaned up dead debug logging/comment blocks and simplified gossip handlers.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/mod_zone_difficulty_scripts.cpp Reworks hot-path hooks to avoid operator[] insertions/double lookups, adds early-outs, and cleans dead debug code.
src/mod_zone_difficulty_handler.cpp Adds IsInstanceMythic(), rewrites lookups to iterator-based access, and refactors phase/override checks.
src/ZoneDifficulty.h Exposes IsInstanceMythic() and updates helper signatures for safer/cheaper calls.
.gitignore Ignores CodeQL detected source root marker file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI and others added 3 commits February 15, 2026 14:05
…d hoist loop-invariant lookup

Co-authored-by: Nyeriah <47818697+Nyeriah@users.noreply.github.com>
Fix OverrideModeMatches global override bug, eliminate redundant lookups, and minor cleanups
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Nyeriah Nyeriah merged commit aac73c4 into azerothcore:master Feb 15, 2026
1 check passed
@Nyeriah Nyeriah deleted the perf branch February 15, 2026 14:30
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.

2 participants

Comments