# Repeated invariant sorting

Rule ID: performance.repeated-sorting@1.0.0. Availability below refers to source-scan at product 524fa07e.

## V-PERF-02 — Repeated invariant sorting

Repeated invariant sorting. It examines repeated work, allocation, traversal, retention, and scheduling cost.

### Availability

Not available in source-scan. There is no source-scan flag to activate this condition.

A separate [experimental source preview](https://docs.swift-analyzer.com/guides/experimental/) recognizes a limited local pattern for this condition:

```text
"$ANALYZER" experimental-scan <path> --rule performance.repeated-sorting --format json
```

Use the terminal from [Installation](https://docs.swift-analyzer.com/get-started/installation/), with ANALYZER set, and replace `<path>` with a Swift file or directory. This preview is not compiler-backed source-scan coverage.

### Example and action

Illustrative pattern only. This is not a complete runnable package or a reproduced source-scan result. Helper APIs and omitted context must be supplied by the application.

```swift
for request in requests {
    respond(request, using: records.sorted(by: order))
}
```

Confirm the operation is on a relevant path and measure with representative input. Preserve evaluation order, laziness, errors and memory behavior when changing the algorithm.

```swift
let sortedRecords = records.sorted(by: order)
for request in requests { respond(request, using: sortedRecords) }
```

### Intended analysis

Intended reasoning: Relate a repeated operation to its input size, consumption and cost assumptions. An intended cost warning needs the loop bounds and actual collection behavior; syntax alone is not a measured runtime regression. Required evidence: cost, multiplicity, collection, allocation, and lifetime facts

### Assumptions and unknown

The relevant facts must be admitted for the selected immutable build world. Unknown aliases, external effects, unsupported source forms or incomplete consumers can prevent a conclusion. Availability in this workflow is stated above; the illustration does not expand that availability.

### Evidence and interpretation

The target catalog describes the intended condition. It is not evidence of an active source-scan diagnostic.

Historical evidence at 4558458d: recovery-required (historical qualification is incomplete and needs further evidence). That evidence has not been requalified for this product revision.

[How we validate checks](https://docs.swift-analyzer.com/concepts/validation/) explains the evidence boundary. [Foundations](https://docs.swift-analyzer.com/concepts/foundations/) separates method assumptions from implementation claims.


---

Language: en
Canonical: https://docs.swift-analyzer.com/catalog/performance.repeated-sorting/
Product revision: 524fa07e0ae4153c84ac12ae9eb6559df89ec2be
Catalog revision: 4558458d
Documentation digest: 1f17ba58ab08627e0de898f1442067b09e960b48cd5605d6529e9275f8930d68
Channel: pre-prod; maturity: experimental; access: owner-provided checkout.
