# Performance and execution cost

The purpose is to catch **real, significant repeated work**, not to enforce numerical budgets or optimize small code prematurely.

## RCS-PERF-001 — Review work across call paths

**Level:** Required when the changed or invoked path reads large data, does expensive external work, repeats in a batch, or contains consequential latency.

**Enforcement:** Transitive call-path review, targeted instrumentation and representative synthetic measurements when useful.

Count actual expensive calls along the *entire action path*: an apparently harmless native file check may call helpers that each hash a multi-gigabyte source. Distinguish checks that prove a new safety fact from redundant scans of the same protected object.

Poor shape (illustrative pseudocode):

```
let first = inspect_entire_file(path)?;
let size = inspect_entire_file(path)?.byte_length();
let hash = inspect_entire_file(path)?.sha256();
```

Better *when the data is qualified for reuse within the same stable observation*:

```
let observed = inspect_entire_file(path)?;
let size = observed.byte_length();
let hash = observed.sha256();
```

In real code, `inspect_entire_file` is a project-owned helper; these snippets are schematic. **Do not cache mutable disk data across unrelated verification boundaries** or weaken source/target identity, concurrency or recovery invariants merely to avoid I/O.

For large sources, stream bytes through one bounded buffer and update all necessary digests and counters in a single pass where safe. Do not substitute an unbounded `fs::read` for streaming just to reduce call counts.

On repeated per-item paths, also inspect unnecessary allocation and copying: `.clone()`, `.to_owned()`, `.to_string()`, temporary buffers, and `.collect()` used only to iterate once over an intermediate vector. Check **what gets copied, how frequently, and how many bytes**, not merely whether a clone appears in source. A stable borrowed slice or simple iterator may avoid the repeated work. `Arc::clone` and `Rc::clone` share ownership rather than deep-copying the payload, so assess them differently from `String` or `Vec` clones.

Retaining an owned value is often correct across a worker handoff, asynchronous lifetime, transaction, snapshot, or recovery boundary. Do not trade away those contracts for an allocation count. Measure uncertain costs on an owned representative workload rather than reporting an imagined speedup.

A useful finding documents: action → nested call chain → number of full passes or queries → size/frequency → effect on time/I/O → which checks are actually independent → smallest safe correction. The count is evidence, not a hard pass/fail quota.

## RCS-PERF-002 — Optimize with evidence

**Level:** Advisory.

**Enforcement:** Review, profiles, measurements and regression tests if appropriate.

Prefer simple idiomatic code until a measurable or strongly bounded cost matters. Explain the baseline, proposed algorithm and safety tradeoff.

Before introducing concurrency, caching or elaborate adapters, ask whether it addresses the true bottleneck and what failure modes it adds. Benchmark with synthetic and controlled data; performance results from one machine do not imply identical throughput on HDDs, SSDs, USB drives and network mounts.

A larger cohesive function may be easier to review and faster than a deeply layered micro-abstraction. Neither line count nor "number of defensive checks" is itself a flaw.

[Back to standards index](<https://rcs.zevarix.com/standards/index.md>).
