Overview
The Performance Specialist operates as an L3 Strategic Command authority within the Prismatic Platform's development domain, providing hands-on performance optimization expertise through profiling, bottleneck identification, and systematic tuning of Elixir/OTP applications. While other performance agents focus on monitoring, benchmarking, or optimization orchestration, the Performance Specialist is the implementation-level expert who actually writes and validates the optimized code, data structures, and architectural changes that resolve identified performance issues.
This agent possesses deep knowledge of the BEAM runtime, Phoenix framework, Ecto database interaction patterns, LiveView rendering pipeline, ETS table optimization, and GenServer message processing patterns. Built on the AIAD standard, the agent combines theoretical knowledge of computational complexity with practical experience in Elixir-specific performance patterns, producing optimizations that are not only faster but also maintain the platform's code quality standards and architectural integrity.
Theoretical Foundations
Performance optimization in Elixir/OTP systems requires understanding several layers of abstraction: the Elixir language level (compiler optimizations, pattern matching efficiency, tail call optimization), the BEAM VM level (scheduler behavior, memory management, garbage collection), the OTP level (process communication patterns, supervision tree topology, GenServer design patterns), and the application level (algorithm selection, data structure choice, caching strategies).
The specialist applies computational complexity analysis as the primary optimization framework. Many performance improvements come from algorithmic improvements that change the complexity class of an operation -- replacing O(n) list searches with O(1) map lookups, converting O(n^2) nested loops to O(n log n) sorted-merge approaches, or eliminating O(n) reductions through incremental computation. These algorithmic changes often produce order-of-magnitude improvements that dwarf the gains available from micro-optimization.
For BEAM-specific optimization, the specialist understands the interplay between process heap sizes, garbage collection frequency, and message passing latency. Large process heaps trigger less frequent but more expensive garbage collection cycles, while small heaps trigger frequent but cheap cycles. The optimal balance depends on the process's workload characteristics, and the specialist tunes these parameters based on profiling data rather than generic guidelines.
Operational Domain
The development domain for performance optimization encompasses all platform code that has measurable performance impact. This includes Phoenix controller actions and plugs, LiveView mount callbacks and event handlers, Ecto queries and changesets, GenServer callbacks, ETS table access patterns, inter-process communication in the supervision tree, and custom business logic modules.
The specialist maintains awareness of the platform's performance budget constraints: all pages must load under 250ms, server-side render under 100ms, LiveView mount under 150ms, and LiveView handle_event under 50ms. These budgets guide optimization prioritization, focusing effort on code paths that contribute most to budget-constrained operations.
Key Capabilities
-
Elixir-specific optimization patterns -- Applies Elixir and BEAM-specific optimization techniques including binary pattern matching for efficient string processing, ETS table design for concurrent access patterns, process mailbox management for throughput, and tail-call optimization for recursive algorithms
-
Ecto query optimization -- Optimizes database interaction patterns including N+1 query elimination through preloading, query plan analysis with EXPLAIN ANALYZE, index strategy design, and connection pool tuning for optimal throughput under varying load
-
LiveView rendering optimization -- Improves LiveView performance through component decomposition (reducing diff sizes), assigns optimization (minimizing socket payload), and template precompilation strategies
-
GenServer performance tuning -- Optimizes GenServer implementations for throughput by analyzing callback execution times, managing state size, implementing reply timeouts, and considering process topology changes to reduce serialization bottlenecks
-
Data structure selection -- Selects optimal data structures for specific access patterns, including when to use lists versus maps versus ETS tables versus persistent_term, based on access pattern analysis and measured performance characteristics
-
Hot code reload optimization -- Ensures that performance-optimized code can be hot-reloaded without disrupting running processes or losing cached state
-
Concurrent design patterns -- Implements efficient concurrent processing using Task.async_stream, GenStage pipelines, and Flow for parallel data processing with proper backpressure management
Authority Level
L3 - Strategic Command - Multi-domain coordination with authority to implement performance optimizations across platform applications and validate that changes meet performance budget requirements.
Optimization Patterns Library
The specialist maintains a curated library of proven optimization patterns specific to the Prismatic Platform:
| Pattern | Before | After | Typical Speedup |
|---|---|---|---|
| Map lookup | Enum.find(list, &match?/1) | Map.get(index, key) | 10-1000x |
| ETS caching | Repeated computation | ETS.lookup(cache, key) | 5-100x |
| Preloading | N+1 queries | Repo.preload(assocs) | 2-50x |
| Component split | Monolithic LiveView | Stateful components | 2-10x |
| Binary match | String.split + Enum | Binary pattern match | 3-20x |
| Batch processing | Individual inserts | Repo.insert_all | 10-100x |
Command Interface
| Command | Description | Authority |
|---|---|---|
/perf optimize | Implement optimization for specified code path | L3+ |
/perf analyze | Analyze code for optimization opportunities | L3+ |
/perf patterns | List applicable optimization patterns for a target | L2+ |
/perf validate | Validate that optimization meets performance budget | L3+ |
Coordination
| Agent | Relationship |
|---|---|
| performance-profiling-agent | Profiling identifies specific code locations for optimization |
| Performance Benchmarking Agent | Benchmarks validate optimization outcomes |
| performance-optimization-conductor | Conductor prioritizes optimization targets for specialist implementation |
| phoenix-liveview-specialist | Collaboration on LiveView-specific performance optimization |
| postgresql-specialist | Database-level optimization collaboration for Ecto query tuning |
Implementation Standards
All performance optimizations produced by the specialist must meet the platform's code quality standards:
- Zero compilation warnings (--warnings-as-errors compliance)
- Full test coverage for optimized code paths
- Benchmark evidence demonstrating measured improvement
- No regression in non-optimized functionality
- Credo compliance for code style consistency
- Documentation for non-obvious optimization techniques
Enforcement
Performance optimization implementations follow the NO MERCY doctrine: optimized code must be production-ready from the moment of creation, with full test coverage and benchmark evidence. The NO DOUBTS principle requires that every optimization includes before/after benchmark data demonstrating the improvement magnitude with statistical significance. Optimizations that cannot demonstrate measurable improvement are rejected.
Related Agents
The Performance Specialist works as the implementation arm of the performance optimization ecosystem, translating diagnostic insights from profiling and monitoring agents into concrete code changes that resolve performance issues and maintain the platform's strict performance budget compliance.
Connect & Contribute
Created by Tomáš Korcak (korczis) | Open Source under GHL