Koan Performance Optimization

VerifiedSafe

Provides patterns for streaming large datasets, batch operations, fast metadata-based counts, and pagination in Koan applications. Helps optimize performance by avoiding memory overflows, reducing query counts, and accelerating bulk operations. Use when scaling applications or facing performance bottlenecks.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude CodeCursorWindsurfCopilotCodex
#performance#streaming#pagination#bulk-operations#optimization

Recommended for

Automated summary

This pattern provides performance strategies for large datasets: streaming, pagination, optimized counting, and bulk operations.

Strengths

  • Provides concrete strategies (streaming, bulk, fast count)
  • Includes quantified benchmarks showing dramatic speedups
  • Offers a pagination pattern with total count for web APIs
  • Covers common antipatterns with correct alternatives

Limitations

  • Specific to the Koan library, not universal
  • Benchmarks are idealized and may vary in practice
  • Does not cover caching or indexing aspects
When to use it

Use this pattern when dealing with large datasets and needing to optimize database query performance.

When not to use it

Avoid this pattern for small data volumes or when code simplicity matters more than micro-optimizations.

Security analysis

Safe
Quality score92/100

The skill provides safe programming advice for .NET environments. No shell commands, file deletions, network calls, or risky operations are instructed. Code snippets are purely illustrative.

No concerns found

How this analysis is made

Examples

Stream large dataset
How can I efficiently process 1 million records from the database without running out of memory? Show me streaming.
Fast count for pagination
I need a fast count of total records for my API pagination. How to get it in milliseconds instead of seconds?
Bulk insert 1000 items
I have 1000 todos to insert efficiently. How to bulk save them in a single operation?

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)

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

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

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

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

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

Pagination

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)

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/koan-performance-optimization-mm5t89wa' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/koan-performance-optimization-mm5t89wa/download' --output '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md.part' && mv '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md.part' '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md' && test -s '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/koan-performance' && cp -R '.skill-downloads/koan-performance-optimization-mm5t89wa' '.claude/skills/koan-performance'

Cursor
test -f '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md' && test -s '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/koan-performance' && cp -R '.skill-downloads/koan-performance-optimization-mm5t89wa' '.cursor/skills/koan-performance'

Codex
test -f '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md' && test -s '.skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/koan-performance' && cp -R '.skill-downloads/koan-performance-optimization-mm5t89wa' '.agents/skills/koan-performance'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/koan-performance-optimization-mm5t89wa'

openskills read 'koan-performance-optimization-mm5t89wa'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/koan-performance-optimization-mm5t89wa/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills