Repository navigation
Add fine-grained benchmark instrumentation to main loop and AI - #4229
Open
sctnightcore wants to merge 1 commit into
Open
sctnightcore wants to merge 1 commit into
sctnightcore wants to merge 1 commit into
Conversation
Wrap the hot paths of the main loop and the AI subsystem in Benchmark::begin/end domains guarded by `if DEBUG`, so the existing benchmark report shows where iteration time is actually spent. Instrumented: interface sleep/iterate, module reload queue, command input and the mainLoop_* init phases, server/client receive, parseMsg, Poseidon replies, task manager rescheduling and task execution, bus events, auto-restart/conf-change/title handling, AI prepare steps, the manual and automatic AI parts, slave and homunculus iteration, the plugin hooks (AI_start/AI_pre/AI_middle/AI_post, mainLoop_pre/post, shouldDropTarget) and the packet parse/mangle/reconstruct path. Also add the missing Utils::Benchmark imports and the Carp::Assert `use` required for the DEBUG constant, and balance the begin/end pairs on the early-return paths in functions.pl, AI/CoreLogic.pm and AI/Attack.pm so no domain is left open.
alisonrag
approved these changes
Oct 13, 2026
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.
Description
Adds
Benchmark::begin/Benchmark::enddomains (all guarded byif DEBUG, so they compile out underNDEBUG) around the hottest paths of the main loop and the AI subsystem, so the existing benchmark report can attribute iteration time to individual steps.Instrumented areas
Interface::mainLoopsleep/iterate, plus the same inInterface::Wx::iteratesrc/functions.pl) — module reload queue, command input, queuedCommands::run, theSTATE_*init phases,mainLoop_pre/mainLoop_posthooks, server/client receive,parseMsg, Poseidon replies, task manager iteration, bus events, auto-restart, auto config change, window titlesrc/AI/CoreLogic.pm) — prepare steps (wipe/avoid/player info/misc/portals), manual AI parts 1.1–1.4, automatic AI parts 2–5, and theAI_start/AI_pre/AI_middle/AI_posthooksprocess/mainflow, includingai_attack_targetSearch,ai_attack_hookand parts 2.1–2.3src/Network/PacketParser.pm) —parse_prehook, parse, mangle and reconstructCorrectness fixes included
Several early-
returnpaths skipped the matchingBenchmark::end, which would leave a domain open and skew the report. These are balanced infunctions.pl,AI/CoreLogic.pmandAI/Attack.pm(e.g. the Poseidon reply short-circuit, the$quitchecks, theprocessClientSuspend()early exit, and the target-search/approach-reset returns inAI::Attack::main).Also adds the missing
use Utils::Benchmark;imports and theuse Carp::Assert;needed for theDEBUGconstant.Notes for review
Benchmark.pmis a no-op stub when the XS module is not compiled, and every call isif DEBUG-guarded, so there is no runtime cost in normal builds.perl -clocally: this checkout has no builtXSToolsXS module, so any module fails atBEGINonuse XSToolsregardless of these changes. Worth a quick smoke test on a machine with the XS modules built (debug 1+debugBenchmarkoutput) before merging.