# ufo-match Performance Benchmark Results

Generated: 2026-07-20
Iterations per benchmark: 10,000,000 (tree search: 1,000,000)
Environment: Chez Scheme with Akku

## How to run

```sh
. .akku/bin/activate
export CHEZSCHEMELIBDIRS=".:$CHEZSCHEMELIBDIRS"
scheme --script tests/bench-ufo-match.sps
```

## Results by commit

| Test | 2f8441c (baseline) | 80aaf53 (current, with cache) |
|---|---:|---:|
| simple list match | 186 | 240 |
| simple list hand-written | 234 | 303 |
| ellipsis match | 1088 | 1353 |
| ellipsis hand-written | 1103 | 1377 |
| nested pattern match | 163 | 176 |
| nested pattern hand-written | 180 | 193 |
| non-linear pattern match | 35 | 39 |
| record `$` match | 1396 | **878** |
| record `&` match | 4381 | **893** |
| record hand-written | 77 | 83 |
| tree search `***` | 57 | 60 |
| many clauses match | 41 | 41 |
| many clauses cond | 38 | 41 |

Times are CPU milliseconds. Numbers vary slightly between runs due to system load; focus on relative differences.

## Key improvement

Record matching was optimized by caching `record-accessor` / `record-mutator` procedures per RTD and field. This avoids rebuilding the field-name→index mapping on every field access.

- `record $ match`: 1396 ms → 878 ms (~37% faster)
- `record & match`: 4381 ms → 893 ms (~80% faster)

`&` patterns now perform essentially the same as `$` patterns.

## Remaining bottleneck

Record matching is still ~10–11× slower than direct field access. Further improvement would require generating direct accessor calls at macro-expansion time (e.g. `employee-name` instead of `record-accessor` reflection), which needs more invasive changes to support named field lookup at compile time.
