# Free AI optimization case study

> Canonical page: https://codevetter.com/benchmark/optimization/free-ai

A one-pass model-selection loop removed an intermediate array and improved every tested registry size without growing the patch.

## Result

- Decision: confirmed
- Observation date: 2026-08-14
- Primary metric: Largest tested registry — 29.8% faster
- Measurement note: 0.016568 → 0.011624 ms/op at 79 models
- Availability: Uses the current local Vitest performance path.

## Tested boundary

- Flow: test/select-model-performance.spec.ts — model selection scales across the supported registry size
- Source: src/router/select-model.ts:171
- Revision: 23ed8566bb1b1d8d86ee1f9890aa4ad5bba9cd18
- Correctness: 241 tests in 37 files passed, plus typecheck and changed-file lint.
- Patch cost: 1 file, 45 gross changed lines, net -7, 0 production dependencies

## Decision path

- **Allocation hotspot in selectCandidates (observed):** 84.1% of initial sampled allocation bytes pointed at the source.
- **Build the ranked list directly (tested):** 10 interleaved samples per side covered three registry sizes.
- **Faster with less code (confirmed):** The candidate removed seven net lines, added no dependency, and passed the bounded change-cost policy.

## Limitations

- This proves one synthetic local model-registry workload up to the repository's current 79-model registry; it does not establish production request latency or customer impact.
- Sampled heap bytes include allocations that may later be collected and are not retained-heap measurements.
- Peak RSS is sampled process-tree evidence and includes the runtime and test runner.
- No production endpoint, provider API, cloud resource, package installation, deployment, paid model, or secret operation was used.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
