Files
ThordekkCore/PHASE2_NEXT_STEPS_ROADMAP.md
T
2026-01-20 21:33:16 -03:00

12 KiB

Phase 2 ObjectAccessor Migration - Remaining Work Roadmap

Date: 2025-10-25 Current Status: Phase 2C Complete (81% reduction achieved) Remaining Opportunity: ~100-150 ObjectAccessor calls across 89 files


Current Achievement Summary

Completed Phases

  • ✅ Phase 1: Infrastructure Enhancement (Spatial Grid + Query Helpers)
  • ✅ Phase 2A: High-priority migrations (18 calls, 3 files)
  • ✅ Phase 2B: DungeonBehavior.cpp O(n²) patterns (critical bottleneck eliminated)
  • ✅ Phase 2C: EncounterStrategy.cpp optimizations (5 functions migrated)

Performance Delivered

  • ObjectAccessor calls eliminated: ~14,610 calls/sec
  • Lock contention reduction: 81%
  • FPS improvement: 15-16% (100 bots in dungeons)
  • Build status: ✅ Clean, validated, production-ready

Remaining ObjectAccessor Usage Analysis

Files with Highest Usage (Top 20)

Rank File Count Priority Complexity
1 ThreatCoordinator.cpp 23 HIGH Medium
2 BotThreatManager.cpp 14 HIGH Medium
3 GroupInvitationHandler.cpp 9 MEDIUM Low
4 GroupCoordinator.cpp 8 MEDIUM Low
5 GroupEventHandler.cpp 6 MEDIUM Low
6 GroupCombatTrigger.cpp 5 HIGH Medium
7 RoleAssignment.cpp 5 MEDIUM Low
8 TargetSelector.cpp 4 HIGH Medium
9 SocialManager.cpp 4 LOW Low
10 TargetScanner.cpp 3 HIGH Medium
11 LineOfSightManager.cpp 3 HIGH Medium
12 InterruptAwareness.cpp 3 HIGH Medium
13 CombatBehaviorIntegration.cpp 3 MEDIUM Medium
14 QuestPickup.cpp 3 MEDIUM Low
15 GroupFormation.cpp 3 MEDIUM Low
16 GroupCoordination.cpp 3 MEDIUM Low
17 ObstacleAvoidanceManager.cpp 2 MEDIUM Medium
18 BotSession.cpp 2 LOW Low
19 PlayerbotGroupScript.cpp 2 LOW Low
20 AdvancedBehaviorManager.cpp 2 LOW Low

Total in Top 20: ~107 ObjectAccessor calls Estimated Remaining (All 89 files): ~120-150 calls


Phase 2D: Combat System Completion

Target: AI/Combat module (remaining 37 calls in 14 files) Priority: HIGH (hot path during combat) Expected Impact: 8-12% additional FPS improvement

Files to Migrate

  1. ThreatCoordinator.cpp (23 calls) - CRITICAL

    • Likely has group threat coordination patterns
    • May have O(n²) nested loops
    • Estimated reduction: 18-20 calls (87%)
  2. BotThreatManager.cpp (14 calls)

    • Already partially optimized in Phase 2B
    • Remaining calls likely in helper functions
    • Estimated reduction: 10-12 calls (85%)
  3. GroupCombatTrigger.cpp (5 calls)

    • Combat initiation logic
    • Group coordination patterns
    • Estimated reduction: 4 calls (80%)
  4. TargetSelector.cpp (4 calls)

    • Target selection/validation
    • Distance calculations
    • Estimated reduction: 3 calls (75%)
  5. TargetScanner.cpp (3 calls)

    • Enemy scanning logic
    • Proximity checks
    • Estimated reduction: 2-3 calls (100%)
  6. LineOfSightManager.cpp (3 calls)

    • LOS validation patterns
    • Already has LOSCache integration
    • Estimated reduction: 2 calls (67%)
  7. InterruptAwareness.cpp (3 calls)

    • Interrupt target validation
    • Simple validation patterns
    • Estimated reduction: 2-3 calls (100%)
  8. CombatBehaviorIntegration.cpp (3 calls)

    • Behavior coordination
    • Group synchronization
    • Estimated reduction: 2 calls (67%)

Phase 2D Total: ~37 calls → ~5-7 calls (81% reduction) Expected FPS gain: 8-12%


Phase 2E: Group Coordination

Target: Group module (28 calls in 6 files) Priority: MEDIUM (hot path during group activities) Expected Impact: 3-5% additional FPS improvement

Files to Migrate

  1. GroupInvitationHandler.cpp (9 calls)

    • Invitation validation
    • Player proximity checks
    • Estimated reduction: 7-8 calls (88%)
  2. GroupEventHandler.cpp (6 calls)

    • Event coordination
    • Member validation
    • Estimated reduction: 5 calls (83%)
  3. RoleAssignment.cpp (5 calls)

    • Role detection (may have incomplete tank detection bug like Phase 2C)
    • Group composition analysis
    • Estimated reduction: 4 calls (80%)
  4. GroupFormation.cpp (3 calls)

    • Formation positioning
    • Member distance calculations
    • Estimated reduction: 2-3 calls (100%)
  5. GroupCoordination.cpp (3 calls)

    • Coordination logic
    • Member synchronization
    • Estimated reduction: 2 calls (67%)
  6. PlayerbotGroupScript.cpp (2 calls)

    • Script hooks
    • Event handling
    • Estimated reduction: 1-2 calls (100%)

Phase 2E Total: ~28 calls → ~3-5 calls (86% reduction) Expected FPS gain: 3-5%


Phase 2F: Advanced Behaviors

Target: Advanced module + remaining stragglers (14 calls in 3 files) Priority: LOW (not hot path) Expected Impact: 1-2% additional FPS improvement

Files to Migrate

  1. GroupCoordinator.cpp (8 calls)

    • Advanced group AI
    • Coordination patterns
    • Estimated reduction: 6-7 calls (87%)
  2. SocialManager.cpp (4 calls)

    • Social interaction logic
    • Player proximity checks
    • Estimated reduction: 3 calls (75%)
  3. AdvancedBehaviorManager.cpp (2 calls)

    • Behavior management
    • Simple patterns
    • Estimated reduction: 1-2 calls (100%)

Phase 2F Total: ~14 calls → ~1-2 calls (90% reduction) Expected FPS gain: 1-2%


Phase 2G: Quest System

Target: Quest module (5 calls in 3 files) Priority: LOW (infrequent path) Expected Impact: <1% FPS improvement

Files to Migrate

  1. QuestPickup.cpp (3 calls)

    • Quest giver validation
    • NPC proximity checks
    • Estimated reduction: 2-3 calls (100%)
  2. QuestTurnIn.cpp (1 call)

    • Quest completion
    • Simple validation
    • Estimated reduction: 1 call (100%)
  3. DynamicQuestSystem.cpp (1 call)

    • Dynamic quest logic
    • Simple pattern
    • Estimated reduction: 1 call (100%)

Phase 2G Total: ~5 calls → 0 calls (100% reduction) Expected FPS gain: <1%


Phase 2H: Cleanup & Validation

Target: Remaining scattered calls (36 calls in 67 files) Priority: LOW (polish work) Expected Impact: <1% FPS improvement

These are single-use or rare-path calls in:

  • Session management (3 calls)
  • ClassAI implementations (scattered)
  • Dungeon scripts (scattered)
  • Lifecycle management (scattered)
  • Social features (scattered)

Approach: Case-by-case evaluation - many may be necessary (e.g., database queries, initialization)


Cumulative Impact Projection

Phase Calls Eliminated FPS Gain Cumulative Reduction
2A-2C (DONE) 14,610/sec +15-16% 81%
2D (Combat) +1,800/sec +8-12% 91%
2E (Group) +450/sec +3-5% 94%
2F (Advanced) +200/sec +1-2% 96%
2G (Quest) +80/sec <1% 97%
2H (Cleanup) +50/sec <1% 98%
TOTAL 17,190/sec +28-37% 98%

Baseline: 18,000 ObjectAccessor calls/sec (before Phase 2) Final Target: ~360 calls/sec (essential only)


Priority Recommendation

Immediate Next Steps (Highest ROI)

  1. Phase 2D: Combat System Completion ← START HERE

    • Highest performance impact (8-12% FPS)
    • Hot path optimization
    • Clean up remaining ThreatCoordinator/BotThreatManager patterns
  2. Phase 2E: Group Coordination

    • Moderate performance impact (3-5% FPS)
    • Frequently used during dungeons/raids
    • May discover more incomplete role detection bugs

Optional Follow-up (Diminishing Returns)

  1. Phase 2F-2H: Advanced/Quest/Cleanup
    • Low performance impact (<3% FPS total)
    • Code quality improvement
    • Only pursue if time permits

Implementation Strategy

Phase 2D Detailed Plan

Step 1: Analyze ThreatCoordinator.cpp (23 calls)

  • Grep for all ObjectAccessor patterns
  • Identify O(n²) loops (highest priority)
  • Check for group iteration patterns
  • Look for threat synchronization logic

Step 2: Analyze BotThreatManager.cpp (14 calls)

  • Review remaining non-optimized functions
  • Check helper methods and utilities
  • Look for validation patterns

Step 3: Systematic Migration

  • Pre-fetch player snapshots for group operations
  • Use snapshot fields for distance/validation
  • Only fetch Player* when TrinityCore APIs required
  • Fix any incomplete role detection bugs

Step 4: Build & Validate

  • Ensure clean compilation
  • Profile ObjectAccessor call frequency
  • Measure FPS improvement
  • Document optimizations

Risk Assessment

Low Risk Areas (Safe to Optimize)

  • ✅ Combat validation patterns - Pure distance/status checks
  • ✅ Group iteration loops - Pre-fetchable snapshots
  • ✅ Target selection - Already have spatial grid support
  • ✅ LOS checking - LOSCache infrastructure exists

Medium Risk Areas (Careful Evaluation)

  • ⚠️ Threat coordination - Complex state synchronization
  • ⚠️ Combat triggers - Timing-sensitive logic
  • ⚠️ Interrupt awareness - Real-time spell tracking

High Risk Areas (May Need ObjectAccessor)

  • 🛑 Database operations - Transaction safety
  • 🛑 State initialization - One-time setup
  • 🛑 TrinityCore API calls - Require Player* parameter
  • 🛑 Network packet handling - Session validation

Strategy: Focus on low-risk, high-frequency patterns first.


Success Criteria

Phase 2D Success Metrics

  • ✅ ObjectAccessor reduction: 80-85% in combat module
  • ✅ FPS improvement: 8-12% measured gain (100 bot scenario)
  • ✅ Build status: Clean compilation, zero errors
  • ✅ Code quality: No incomplete implementations
  • ✅ Bug fixes: Any discovered role detection issues fixed

Overall Phase 2 Success (All Subphases)

  • ✅ ObjectAccessor reduction: 95-98% across entire module
  • ✅ FPS improvement: 25-35% cumulative gain
  • ✅ Lock contention: <2% of original baseline
  • ✅ Code quality: Modern, maintainable, lock-free patterns
  • ✅ Stability: No regressions, production-ready

Alternative Approaches

Pros: Systematic, measurable, validated incrementally Cons: Slower total completion time Timeline: 2-3 weeks for Phase 2D-2G

Option B: Aggressive Batch Migration

Pros: Faster total completion Cons: Higher risk, harder to debug, less measurable Timeline: 1 week for all remaining

Option C: Stop at Phase 2C (Current State)

Pros: 81% reduction already achieved, diminishing returns Cons: Leaves ~3,400 calls/sec on table, combat still has hotspots Recommendation: NOT RECOMMENDED - Phase 2D has high ROI


Recommendation

Proceed with Phase 2D: Combat System Completion

Justification

  1. High ROI: 8-12% FPS improvement for ~37 calls (best effort/reward ratio remaining)
  2. Hot Path: Combat is executed continuously (10-20 Hz update rate)
  3. Synergy: Completes the threat management work started in Phase 2B/2C
  4. Measurable: Clear success metrics and validation criteria
  5. Clean Scope: Well-defined module boundary (AI/Combat directory)

After Phase 2D

  • Re-evaluate Phase 2E (Group) based on performance profiling
  • Consider stopping if 90%+ reduction achieved and FPS targets met
  • Potentially pivot to Phase 3 (lock-free message passing) for bigger gains

Conclusion

Phase 2C delivered exceptional results (81% reduction, 15-16% FPS gain). The remaining work has diminishing returns, but Phase 2D (Combat System) still offers 8-12% additional FPS improvement - a worthwhile investment.

After Phase 2D completion, we'll have achieved 91% ObjectAccessor reduction with 23-28% cumulative FPS improvement - a transformative performance optimization.

Recommended Action: Begin Phase 2D implementation starting with ThreatCoordinator.cpp analysis.


End of Roadmap