Files
Library/docs/roadmap/PERFORMANCE.md

8.2 KiB

Performance profiles and measurement plan

Status: planned measurement/optimization work. No speedup or benchmark result is claimed by this document. The existing Bench helper measures individual calls through std::function and a clock; it is useful functionality but is not yet a comparative library-wide performance suite.

Goals and profiles

Runtime and memory have priority. Separate profiles make tradeoffs visible rather than forcing one tuning policy onto every consumer.

Profile Primary metrics Constraints and representative work
Latency p50/p95/p99 operation and queue latency; deadline misses Small RPC/HTTP requests, task wakeups, service lookup, log admission, point reads; bounded queues and no hidden blocking
Throughput Completed operations/second, bytes/second, CPU per useful operation Streaming transfers, serialization, batches, message consumption, multi-client workloads; report queue depth and fairness
Footprint Allocation count/bytes, peak and retained RSS, working set, binary size Small consumers, bounded queues, snapshots, caches and idle runtime; peak includes in-flight batches/buffers
Developer cost Clean/incremental compile time, link time, dependency closure, artifact size Single-header consumers, selected modules, complete shared/static installs; tracked alongside runtime profiles

Each module plan chooses relevant scenarios and explicit resource limits. A low-latency configuration may trade throughput or memory; publish that tradeoff. An optimization cannot be accepted by excluding failed, rejected, timed-out, or dropped work from the reported totals without reporting those counts separately.

Reproducible workload specification

Every benchmark record includes source revision, dirty state, compiler/standard-library versions, flags, dependency versions, OS/kernel, CPU model/core topology, memory, storage device/filesystem for I/O, affinity policy, power policy, data set and random seed, thread/client count, warmup, duration/sample count, and requested module/profile options. Do not record credentials or production payloads. Use generated or public fixture data.

Use release-optimized builds for performance results, with a separate instrumented build for allocation/fault investigations when instrumentation changes timing. Keep baseline and candidate workloads identical. Record raw samples in a machine-readable artifact plus a human summary. Preserve correctness assertions outside the timed critical section where possible and validate every run's outputs.

For initial comparisons use five warmup runs and at least twenty measured repetitions of each aggregate workload. Increase duration/repetitions if confidence intervals overlap too much to distinguish a claimed effect; never select only favorable runs. For extremely small functions batch many operations per timed interval and subtract/report a separately measured harness baseline. Do not interpret clock/dispatch overhead as the function's intrinsic cost. Network latency workloads retain per-request samples and avoid hiding queueing by driving clients only after each previous request finishes.

Measurement and acceptance rules

  1. Establish the workload's current baseline before changing algorithms or defaults.
  2. Select the primary metric and resource budgets in the task contract before measuring the candidate. Hard resource bounds are correctness criteria, not statistical targets.
  3. Report median aggregate results with 95% confidence intervals and p95/p99 for operation-level latency. Record failed/rejected work and maximum observed resource use.
  4. A performance improvement requires a repeatable effect larger than observed noise, preserved correctness, and satisfaction of the selected profile's resource budgets.
  5. Flag a regression exceeding 5% in a non-target metric on the controlled benchmark host when repeated runs distinguish it from noise. Resolve it or record an explicit profile tradeoff before acceptance. Shared/noisy CI measurements are advisory.
  6. No universal absolute latency or speedup target is asserted before hardware/workload baselines exist. Once established, commit versioned per-workload budgets and require a deliberate reviewed change to revise them.

Benchmark inventory

Family Scenarios Important controls
Core/containers/memory Small/large values, sparse/dense keys, cache hit/miss, pool reuse, arena reset Lifetime correctness, alignment, bytes retained and allocation failures
Algorithms/math/text Input size distributions, adversarial patterns, scalar/vector paths, UTF validity Identical semantics; compare appropriate standard-library baseline
Data/binary Small objects, deep nesting, large integers, large streams, encode/decode/reflection Validation policies matched; malformed-input throughput separate
Async/IO Uncontended/contended queues, cancellation storms, timer scale, partial I/O Admission counts, fairness, deadline misses and in-flight memory
Net/RPC Cold/warm connections, TLS handshakes, keepalive, slow clients, uploads/downloads Connection reuse, client/server CPU, network topology, total deadlines
Storage/Sqlite Point/range reads, atomic batches, read/write mix, snapshots and compaction Durability/isolation modes matched; dataset larger than cache included
Log/observability Disabled path, small/structured events, saturation, slow exporter, flush Loss policy/counters, queue plus batch memory, cardinality limits
Service/plugin/FSM Lookup, pinned calls during replacement, event/timer fan-out, cancellation No lifetime weakening; reload tail latency and retained generations
Distributed Quorum commit, read-index, leader replacement, snapshot catch-up Fault model, replica placement, acknowledgement semantics, tail latency
Packaging/build Foundation consumer, selected module set, all modules; clean and edit/rebuild Same compiler/cache state; report cold and warm caches separately

Inspected optimization candidates

These are source properties or investigation targets, not measured bottlenecks:

  • HTTP requests currently create connection/TLS state per attempt; compare reusable sessions and streaming against the exact same trust/deadline policy.
  • MPSC delivery allocates nodes; investigate pooling/batched ownership only after concurrent destruction, reclamation, and memory bounds are defined.
  • JSON object lookup, router matching, and FSM timer scans use simple structures; measure workload sizes before replacing them with indexes or timer hierarchies.
  • Log worker batches can grow independently of queued slot accounting; establish a correct total bound before optimizing batch size or lock contention.
  • Header-heavy templates/reflection and broad test linkage affect build cost; measure include/dependency isolation before selecting precompiled-header or module experiments.

Tasks

ID Work Dependencies Acceptance
X-PERF-01 Define workload/result schemas and reproducible runner manifests P0 inventory; Time/Testing measurement contracts Every result identifies configuration and raw samples; seeded repeat is reproducible.
X-PERF-02 Implement aggregate timing, allocation and resource collectors X-PERF-01 Harness overhead measured; counters reconcile; collectors do not change semantic outcomes.
X-PERF-03 Establish foundation/runtime/network/storage baselines Relevant modules available Comparable workloads and profile budgets versioned before optimization.
X-PERF-04 Add controlled-host regression comparison and advisory CI summaries X-PERF-02, X-PERF-03 Noise-aware alerts and explicit tradeoff records; no flaky shared-runner release gate.
X-PERF-05 Profile and optimize one identified cause per task Selected baseline and hypothesis Measured improvement, regression tests, before/after evidence and resource accounting.

All tasks are PLANNED. Runner/benchmark command names are PROPOSED until the harness exists; the only CURRENT commands are the existing build/test commands documented in VALIDATION.md. Cross-area performance work must use those modules' approved ownership and shared contracts.