perf: batch affect_total in CastAffect (#3106)#3118
Merged
Conversation
affect_total() is expensive (~6-10ms with full equipment and 30+ affects) because it iterates all equipment slots × object affects × weapon affects. Previously CastAffect called ImposeAffect in a loop (up to 16 iterations), and each ImposeAffect called affect_total via affect_to_char. This meant N calls to affect_total per spell cast. Add ImposeAffectNoRecalc / affect_to_char_no_recalc variants that skip the affect_total recalculation. CastAffect now uses these and calls affect_total once after the loop. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 11, 2026
Open
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.
Summary
ImposeAffectNoRecalc— variant ofImposeAffectthat skipsaffect_total()recalculationCastAffectloop to useImposeAffectNoRecalc, callaffect_total(victim)once after the loopaffect_totalper spell to exactly 1Context
Profiler data from #3106 shows
affect_total()takes ~6-10ms per call (iterates 20 equipment slots × 8 obj affects × ~48 weapon affects + character affects).CastAffectcalledImposeAffectup to 16 times in a loop, each triggering a fullaffect_totalrecalculation.Test plan
hit()andPlayerAttack🤖 Generated with Claude Code