Skip to content
Back to skills

Koan Performance

ASecurity

Streaming, pagination, count strategies, bulk operations

  • 57 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added May 31, 2026
businessapiperformancedocumentation

Works with

  • api

Security analysis

A100/100

Scanned May 31, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill koan-performance --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Koan Performance?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Koan Performance
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-koan-performance/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-koan-performance)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: koan-performance
description: Streaming, pagination, count strategies, bulk operations
---

# Koan Performance

## Core Principle

**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.

## Performance Patterns

### Streaming (Large Datasets)

```csharp
// ❌ 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);
}
```

### Count Strategies

```csharp
// 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 Operations

```csharp
// 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)
```

### Batch Retrieval

```csharp
// ❌ WRONG: N queries
foreach (var id in ids)
{
    var todo = await Todo.Get(id);
}

// ✅ CORRECT: 1 query
var todos = await Todo.Get(ids);
```

### Pagination

```csharp
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);
}
```

## Performance Benchmarks

| 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 |

## When This Skill Applies

- ✅ Performance tuning
- ✅ Large datasets
- ✅ Optimization
- ✅ Production readiness
- ✅ Memory issues
- ✅ Query optimization

## Reference Documentation

- **Example Code:** `.claude/skills/entity-first/examples/batch-operations.cs`
- **Guide:** `docs/guides/performance.md`
- **Sample:** `samples/S14.AdapterBench/` (Performance benchmarks)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.