with one click
koan-performance
Streaming, pagination, count strategies, bulk operations
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Streaming, pagination, count strategies, bulk operations
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Auto-registration via KoanAutoRegistrar, minimal Program.cs, "Reference = Intent" pattern
Chat endpoints, embeddings, RAG workflows, vector search
Aggregate boundaries, relationships, lifecycle hooks, value objects
Entity<T> patterns, GUID v7 auto-generation, static methods vs manual repositories
Transparent L1/L2 caching for Entity<T>, [Cacheable] attribute, cross-node coherence, per-request opt-out
Run a mandatory pre-implementation exploration workflow before writing production code in Koan (.NET/C#). Use when a task requires code changes and Codex must first map concerns/layers, read relevant files and docs, check existing constants and types, identify the closest existing pattern, plan exact code placement, and confirm architectural guardrails.
| name | koan-performance |
| description | Streaming, pagination, count strategies, bulk operations |
Optimize for scale from day one. Use streaming for large datasets, batch operations for bulk changes, fast counts for UI, and pagination for web APIs.
// ❌ WRONG: Load everything into memory
var allTodos = await Todo.All(); // 1 million records!
// ✅ CORRECT: Stream in batches
await foreach (var todo in Todo.AllStream(batchSize: 1000))
{
await ProcessTodo(todo);
}
// Fast count (metadata estimate - 1000x+ faster)
var fast = await Todo.Count.Fast(ct); // ~5ms for 10M rows
// Exact count (guaranteed accuracy)
var exact = await Todo.Count.Exact(ct); // ~25s for 10M rows
// Optimized (framework chooses)
var optimized = await Todo.Count; // Uses Fast if available
Use Fast for: Pagination UI, dashboards, estimates Use Exact for: Critical business logic, reports, inventory
// Bulk create
var todos = Enumerable.Range(1, 1000)
.Select(i => new Todo { Title = $"Task {i}" })
.ToList();
await todos.Save(); // Single operation
// Bulk removal
await Todo.RemoveAll(RemoveStrategy.Fast); // TRUNCATE/DROP (225x faster)
// ❌ WRONG: N queries
foreach (var id in ids)
{
var todo = await Todo.Get(id);
}
// ✅ CORRECT: 1 query
var todos = await Todo.Get(ids);
public async Task<IActionResult> GetTodos(
int page = 1,
int pageSize = 20,
CancellationToken ct = default)
{
var result = await Todo.QueryWithCount(
t => !t.Completed,
new DataQueryOptions { OrderBy = nameof(Todo.Created), Descending = true },
ct);
Response.Headers["X-Total-Count"] = result.TotalCount.ToString();
return Ok(result.Items);
}
| Operation | Inefficient | Efficient | Speedup |
|---|---|---|---|
| Bulk Remove (1M) | DELETE loop ~45s | TRUNCATE ~200ms | 225x |
| Count (10M) | Full scan ~25s | Metadata ~5ms | 5000x |
| Batch Get (100) | 100 queries | 1 query | 100x |
| Stream (1M) | Load all (OOM) | Stream batches | Memory safe |
.claude/skills/entity-first/examples/batch-operations.csdocs/guides/performance.mdsamples/S14.AdapterBench/ (Performance benchmarks)