Skip to content
Development
Skill

/performant-code

Writing efficient code that handles large data and tight constraints

From plugin
pydantic-deepagents
1.1k14 skills

Claude Code

$ npx -y skills add vstorm-co/pydantic-deepagents --skill performant-code --agent claude-code

SKILL.md

performant-code.SKILL.md
name: performant-code
description: "Writing efficient code that handles large data and tight constraints"
tags: [performance, optimization, benchmark]
version: "1.0.0"

Performant Code

How to write code that won't timeout on large inputs.

Think About Scale First

Before writing code, ask: how big is the data?

| Data size | Approach | |-----------|----------| | < 1 MB | Load into memory, any approach works | | 1-100 MB | Load into memory, but use efficient algorithms | | 100 MB - 1 GB | Stream/mmap, avoid loading entirely into memory | | > 1 GB | Streaming only, chunk-based processing |

I/O Optimization

Large files

  • **mmap** (C: `mmap()`, Python: `mmap.mmap()`) — map file into memory, OS handles paging
  • **Buffered binary reads** — `fread()` in C, `open(f, 'rb').read(chunk)` in Python
  • **NEVER** read a 500MB file line-by-line with `fgets()` when you need random access

Writing output

  • Buffer writes — don't call `write()` for every byte
  • Use `fwrite()` or `sys.stdout.buffer.write()` for binary output
  • Flush only when needed

Algorithm Complexity

  • **O(n)** beats **O(n log n)** beats **O(n²)** — always
  • Nested loops on large data = timeout. Restructure to single pass + hash map
  • Sorting is O(n log n) — only sort if you need to
  • Use hash maps/sets for lookup instead of linear search
  • Pre-compute what you can outside loops

Language-Specific Tips

C

  • Use `mmap()` for large file access
  • `-O2` or `-O3` for compiler optimizations
  • Avoid `malloc()`/`free()` in tight loops — pre-allocate
  • Use `memcpy()` instead of byte-by-byte copying
  • Integer arithmetic > floating point when possible

Python

  • Use `numpy` for numerical work (100x faster than pure Python loops)
  • `collections.Counter`, `defaultdict` — avoid manual counting
  • List comprehensions > explicit loops
  • `struct.unpack()` for binary parsing
  • `subprocess.run()` > `os.system()`
  • For heavy computation: consider writing a small C program instead

General

  • Profile before optimizing — find the actual bottleneck
  • If a program hangs, it's likely: infinite loop, deadlock, or I/O bound on huge data
  • If a program is slow, check: algorithm complexity, I/O pattern, memory allocation

Constraints Awareness

  • If the task says "< 5000 bytes" — count your bytes, use `wc -c`
  • If there's a time limit — test with actual data, not toy inputs
  • If there's a memory limit — don't load everything into RAM
  • Always verify constraints BEFORE declaring done
Read more
@vstorm-co
Ships withpydantic-deepagents

Open-source, self-hosted Claude Code - a terminal AI assistant and the Python framework behind it. Tool-calling, sandboxed execution, multi-agent teams, skills, checkpoints, unlimited context - on Pydantic AI, any model.

Stars on GitHub

Momentum

stars in total
1.1k
Star history of vstorm-co/pydantic-deepagents on GitHub, a chart by star-history.com

Other skills on pydantic-deepagents.

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills11d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc13d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react2d252k
@facebook@facebookInstall Skill

Questions about performant-code.

Which coding agents can use performant-code?
performant-code installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.