perf: O(N*M) -> O(N log N) combat initiative loop (#3106)#3107
Merged
Conversation
e0219de to
2ed98dc
Compare
Двойной цикл initiative(max..min) × combat_list заменён на std::list::sort по инициативе + один проход по списку. Было: до 201 прохода по combat_list (инициативы от -100 до 100). Стало: одна сортировка O(N log N) + один проход O(N). Round check занимал 95% времени perform_violence (130-189ms). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2ed98dc to
7127e2c
Compare
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
Round checkвperform_violenceзанимал 95% времени (130-189ms при пульсе 40ms).Причина: двойной цикл
for (initiative = max..min)×for (combat_list)= O(N×M), где M = до 201 (диапазон инициатив -100..100).Фикс:
combat_list.sort()по убыванию инициативы + один проход = O(N log N + N).Test plan
🤖 Generated with Claude Code