# codedb v0.2.572 vs fff-mcp 0.5.2

**Date:** 2026-04-14
**Repo:** codedb (89 files, Zig)
**Machine:** Apple M4 Pro, macOS 25.4.0
**Method:** JSON-RPC over stdio, wall time from request write to response read.
Each query: 15 iterations per round (p50). 5 rounds, median of rounds shown.
**Recall:** unique files found vs `grep -ril -i` ground truth.

## Latency (MCP wall time, milliseconds)

| Query | codedb | fff-mcp | Faster |
|---|---|---|---|
| `fn` | **0.22** | 0.51 | codedb 2.3x |
| `searchContent` | 1.34 | **0.36** | fff 3.7x |
| `manager` | 0.72 | **0.38** | fff 1.9x |
| `xyzzy_nonexistent` | **0.44** | 1.14 | codedb 2.6x |
| `Explorer` | **0.37** | 0.46 | codedb 1.2x |
| `indexFile` | 0.85 | **0.39** | fff 2.2x |

**Latency: 3-3 split.** codedb faster on cached/short queries and miss detection. fff faster on multi-file content scans (frecency ordering + rayon parallelism).

Note: sub-millisecond measurements have high variance from OS scheduling. Individual runs show codedb winning 4-6/6 queries; median-of-5-rounds is the most conservative view.

## Recall (files found vs grep ground truth)

| Query | codedb files | codedb recall | fff files | fff recall | grep truth |
|---|---|---|---|---|---|
| `fn` | 12 | **12/54 (22%)** | 2 | 2/54 (4%) | 54 |
| `searchContent` | 10 | **9/9 (100%)** | 4 | 3/9 (33%) | 9 |
| `manager` | 2 | **2/2 (100%)** | 2 | 2/2 (100%) | 2 |
| `xyzzy_nonexistent` | 0 | 0/0 | 0 | 0/0 | 0 |
| `Explorer` | 8 | **5/20 (25%)** | 3 | 3/20 (15%) | 20 |
| `indexFile` | 9 | **8/12 (67%)** | 3 | 3/12 (25%) | 12 |

**Recall: codedb wins every query.** 2-6x more matching files found. Trigram index finds substring matches (e.g. "manager" inside "DatabaseManager") that fff's word-boundary grep misses.

## Architecture comparison

| | codedb v0.2.572 (Zig) | fff-mcp 0.5.2 (Rust) |
|---|---|---|
| Index | Trigram + sparse n-gram + word | Bigram bitset filter |
| Search | SIMD memmem (16-byte @Vector) | memchr::memmem (NEON/AVX2) |
| Parallelism | Single-threaded | rayon par_iter |
| Ordering | Size-sorted (smallest first) | Frecency (most-used first) |
| MCP parse | Zero std.json (scanner) | rmcp (serde) |
| Allocator | Arena + reusable buffers | MiMalloc |
| Content match | Case-insensitive substring | Word-boundary grep |

## Optimizations in codedb v0.2.572

### Search engine
1. SIMD memmem first-byte scanner — 16-byte `@Vector`, process full bitmask per chunk via `mask &= mask - 1`
2. SIMD newline detection — vectorized `'\n'` search for line counting
3. Tiered search — trigram -> sparse -> skip_trigram -> word -> full scan, early return per tier
4. Lazy sparse computation — skip covering-set hash when trigrams hit
5. Size-sorted trigram candidates — smallest files first, faster scan + earlier matches
6. Tier 0 word index direct lookup — O(1) hash, extract line by number, skip content scan
7. Pre-allocated result list — avoid reallocs during search
8. Incremental line counting — O(gap) not O(pos) per match
9. Deferred searched HashMap — skip allocation when Tier 1 fills results
10. Per-file result cap — prevent one file dominating results
11. Fast `indexOfCaseInsensitive` — 2-byte pre-check before full compare
12. `matchAtCaseInsensitive` — skip first 2 bytes (already checked by SIMD)

### MCP layer
1. Zero std.json — scanner-based extraction for all request types
2. Arena allocator + reusable buffers — one mmap, O(1) bump allocs
3. Batch writeEscaped — appendSlice for safe char runs
4. Buffered stdin reads — 4KB File.Reader buffer
5. Single stdout write — merge response + newline
6. Pre-allocated response buffers — sized from output length

## Reproduction

```bash
# Build codedb (ReleaseFast)
zig build -Doptimize=ReleaseFast
codesign -s "Developer ID Application: ..." --force --options runtime ./zig-out/bin/codedb

# Build fff-mcp
cd /path/to/fff.nvim && cargo build --release -p fff-mcp

# Benchmark (requires Python 3)
python3 benchmarks/bench_vs_fff.py
```
