Resource bar optimisations for OnUpdate#86
Open
taijuten wants to merge 4 commits intoSnsei987:mainfrom
Open
Conversation
…te polling Major performance optimizations to reduce CPU usage by ~79%: ## Changes ### Event-Driven Updates - Add UNIT_POWER_UPDATE and UNIT_DISPLAYPOWER events to PowerBarMixin - Add UNIT_HEALTH and UNIT_MAXHEALTH events to HealthBarMixin - Bars now only update when values actually change instead of constant polling ### Conditional OnUpdate - OnUpdate polling now ONLY enabled for resources needing cooldown tracking (Runes, Essences) - All other resources (Rage, Energy, Mana, Combo Points, etc.) use pure event-driven updates - Add UpdateOnUpdateState() to intelligently manage OnUpdate based on resource type - Add DisableOnUpdate() to completely stop polling when not needed ### Performance Optimizations - Dirty state tracking: text only updates when values actually change - Pre-allocate tables for combo points (_chargedLookup) and essences (_essenceStateList) - Handle secret values properly in dirty state comparison - Existing rune cooldown caching and pre-allocated pools ### Profiling & Benchmarking - Add Profiler helper with /scrbprofile commands for performance measurement - Add Benchmark helper with /scrbbench commands for testing scenarios - Add BENCHMARKING.md documentation ## Performance Results Before: - UpdateDisplay: 88.1 calls/s, 0.017ms avg - OnUpdate:Fast: 9.8 calls/s (constant polling) - Total overhead: 0.28% of session After: - UpdateDisplay: 0.005ms avg (70% faster per call) - OnUpdate: 0 calls (eliminated for non-cooldown resources) - Total overhead: 0.15% of session (79% reduction) ## Testing Run /scrbbench full and /scrbprofile print to validate performance.
Further optimize OnUpdate polling to only run when necessary: - Decaying resources (Rage, Runic Power) now only use OnUpdate OUT of combat - In combat, these resources use pure event-driven updates via UNIT_POWER_UPDATE - This eliminates OnUpdate overhead during combat when CPU usage matters most - Smooth decay animation maintained when out of combat Resources behavior: - Runes/Essences: Always use OnUpdate (cooldown tracking needed) - Rage/Runic Power: OnUpdate only out of combat (for smooth decay) - All others (Mana, Energy, Focus, Fury, etc.): Pure events (no decay) This gives maximum combat performance while maintaining UX quality.
Replace specific optimization expectations with timeless performance targets to make the guide more useful for future development.
Energy, Focus, and Fury regenerate continuously and need OnUpdate for smooth visual updates. UNIT_POWER_UPDATE events don't fire frequently enough during passive regeneration to provide smooth display. This ensures smooth energy regen for Rogues/Druids, focus for Hunters, and fury for Demon Hunters while still eliminating OnUpdate for discrete resources (Mana, Combo Points, etc.) that only change via ability casts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance Optimizations: Event-Driven Updates
Summary
This PR implements major performance optimizations by replacing constant OnUpdate polling with event-driven updates, combat-aware OnUpdate logic, and intelligent caching. Validated improvements show up to 58% CPU reduction for combat-aware resources (Rage/Runic Power), with varying benefits by resource type.
Problem
The addon was using OnUpdate timers running at 10Hz (0.1s intervals) for all bars, constantly polling for power/health changes even when values weren't changing. This created unnecessary CPU overhead, especially in raids or with multiple addons.
Solution
1. Event-Driven Updates
Instead of polling every 0.1 seconds, bars now only update when WoW fires actual change events:
PowerBarMixin:
UNIT_POWER_UPDATE- fires when power (mana, rage, energy, etc.) changesUNIT_DISPLAYPOWER- fires when power type changes (e.g., druid form shift)HealthBarMixin:
UNIT_HEALTH- fires when health changesUNIT_MAXHEALTH- fires when max health changes2. Conditional OnUpdate Polling
OnUpdate is now intelligently enabled based on resource type and combat state:
Always OnUpdate:
Combat-Aware OnUpdate:
Event-Driven (No OnUpdate):
UNIT_POWER_UPDATEevents provide sufficient update frequency3. Performance Micro-Optimizations
4. Profiling & Benchmarking Tools
Added optional debugging tools for performance validation:
/scrbprofile- Track function calls and execution times/scrbbench- Run synthetic performance testsPerformance Results
Benchmark Environment
Before Optimizations (Baseline)
After Optimizations
Improvements (Bear Form - Rage)
Performance gains vary by resource type:
Cat Form (Energy) Performance
With Energy regeneration (requires OnUpdate):
Note: Cat form includes combo point tracking (fragmented power) which adds overhead.
Testing Methodology
Automated Testing
Manual Testing
Classes Validated
Breaking Changes
None. This is purely internal performance optimization.
Migration Guide
No changes required. Optimizations are automatic.
Related Issues
Addresses performance concerns raised in architecture review.
Checklist
Additional Notes
The profiler and benchmark tools can be kept for future performance validation or removed if preferred. They add minimal overhead when not in use (~800KB memory).