Skip to content

Add fine-grained benchmark instrumentation to main loop and AI - #4229

Open
sctnightcore wants to merge 1 commit into
OpenKore:masterfrom
sctnightcore:perf/benchmark-instrumentation
Open

sctnightcore wants to merge 1 commit into
OpenKore:masterfrom
sctnightcore:perf/benchmark-instrumentation

Conversation

@sctnightcore

Copy link
Copy Markdown
Member

Description

Adds Benchmark::begin/Benchmark::end domains (all guarded by if DEBUG, so they compile out under NDEBUG) 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 — Interface::mainLoop sleep/iterate, plus the same in Interface::Wx::iterate
  • Main loop (src/functions.pl) — module reload queue, command input, queued Commands::run, the STATE_* init phases, mainLoop_pre/mainLoop_post hooks, server/client receive, parseMsg, Poseidon replies, task manager iteration, bus events, auto-restart, auto config change, window title
  • TaskManager — reschedule and per-task execution
  • AI (src/AI/CoreLogic.pm) — prepare steps (wipe/avoid/player info/misc/portals), manual AI parts 1.1–1.4, automatic AI parts 2–5, and the AI_start/AI_pre/AI_middle/AI_post hooks
  • AI::Attack — the whole process/main flow, including ai_attack_targetSearch, ai_attack_hook and parts 2.1–2.3
  • Slaves — per-slave iteration split into homunculus vs mercenary, with manual/auto sub-domains
  • Packet parsing (src/Network/PacketParser.pm) — parse_pre hook, parse, mangle and reconstruct

Correctness fixes included

Several early-return paths skipped the matching Benchmark::end, which would leave a domain open and skew the report. These are balanced in functions.pl, AI/CoreLogic.pm and AI/Attack.pm (e.g. the Poseidon reply short-circuit, the $quit checks, the processClientSuspend() early exit, and the target-search/approach-reset returns in AI::Attack::main).

Also adds the missing use Utils::Benchmark; imports and the use Carp::Assert; needed for the DEBUG constant.

Notes for review

  • Benchmark.pm is a no-op stub when the XS module is not compiled, and every call is if DEBUG-guarded, so there is no runtime cost in normal builds.
  • I could not run perl -c locally: this checkout has no built XSTools XS module, so any module fails at BEGIN on use XSTools regardless of these changes. Worth a quick smoke test on a machine with the XS modules built (debug 1 + debugBenchmark output) before merging.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants