# Requirements Archive: v7.2 Memory Efficiency -- Zero-OOM Sidecar

**Archived:** 2026-03-27
**Status:** SHIPPED

For current requirements, see `.planning/REQUIREMENTS.md`.

---

# Requirements: v7.2 Memory Efficiency

**Defined:** 2026-03-27
**Source:** Memory audit (2-agent), sidecar OOM incident (#313)
**Core Value:** Sidecar operates within 4G MemoryMax without OOM, even during 200K-bar drain from 16-symbol fill_from_rest.

## Requirements

### Arrow FFI — drain_bars_arrow (#313 P0)

- [ ] **ARROW-01**: `StreamManager.drain_bars_arrow()` returns Arrow RecordBatch instead of `list[dict]`
- [ ] **ARROW-02**: `_sync_flush_rest_bars` consumes Arrow RecordBatch with zero-copy Polars slicing per (symbol, threshold)
- [ ] **ARROW-03**: Peak sidecar RSS during drain stays below 2.5G for 200K-bar drain (verified with memray or RSS monitoring)

### Hot-Path Allocation Reduction (#313 P1)

- [x] **ALLOC-01**: Single `OpenDeviationBarCache()` instance reused across `_create_engine` (not 3 separate contexts)
- [x] **ALLOC-02**: `_write_bars_batch_to_clickhouse` accepts Arrow/Polars directly (no dict→DataFrame conversion per flush)
- [x] **ALLOC-03**: `get_symbol_entries()` cached at sidecar startup, not re-called per flush

### Lazy Evaluation (#313 P2)

- [ ] **LAZY-01**: `TickStorage.write_ticks` dedup uses `scan_parquet` for ID-only check (not full file load)
- [ ] **LAZY-02**: Stathera diagnostic sort uses in-place sort or avoids sorted() copy

### Out of Scope

| Feature                                | Reason                                                      |
| -------------------------------------- | ----------------------------------------------------------- |
| Per-symbol flush during fill_from_rest | P0-alt — more invasive Rust change, evaluate after ARROW-01 |
| MemoryMax increase to 6G               | Band-aid — want to stay at 4G                               |

## Traceability

| Requirement | Phase    | Status  |
| ----------- | -------- | ------- |
| ARROW-01    | Phase 23 | Pending |
| ARROW-02    | Phase 23 | Pending |
| ARROW-03    | Phase 23 | Pending |
| ALLOC-01    | Phase 24 | Complete |
| ALLOC-02    | Phase 24 | Complete |
| ALLOC-03    | Phase 24 | Complete |
| LAZY-01     | Phase 25 | Pending |
| LAZY-02     | Phase 25 | Pending |

**Coverage:** 8 requirements, 8 mapped, 0 unmapped
