AIPerf Code Patterns
Code examples for common development tasks. Referenced from CLAUDE.md.
CLI Command Pattern
Commands live in src/aiperf/cli_commands/, one file per command. They are
lazily loaded via import strings in aiperf.cli — modules are only imported
when their command is invoked:
Conventions:
- Export a single
Appnamedapp. - Hyphenate multi-word commands:
App(name="analyze-trace"). - Keep module-level imports minimal; heavy deps go inside the function body.
- Heavy implementation logic lives in a
cli.pyinside the owning domain package (e.g.aiperf/plugin/cli.py), lazily imported at call time.
Service Pattern
Services run in separate processes via bootstrap.py:
Register in plugins.yaml:
Config types:
ServiceConfig: infrastructure (ZMQ ports, logging level)UserConfig: benchmark params (endpoints, loadgen settings)
Model Pattern
Use AIPerfBaseModel for data, BaseConfig for configuration:
Message Pattern
Messages require message_type field and handler decorator:
Auto-subscription happens during @on_init phase.
Plugin System Pattern
YAML-based registry with lazy-loading:
Error Handling Pattern
Log errors and publish ErrorDetails in messages:
Logging Pattern
Use lambda for expensive log messages:
Testing Pattern
Auto-fixtures (always active): asyncio.sleep runs instantly, RNG=42, singletons reset.