Skip to content
cccskills
FreePublished on GitHub

performant-code

Writing efficient code that handles large data and tight constraints

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md2.5 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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 sizeApproach
< 1 MBLoad into memory, any approach works
1-100 MBLoad into memory, but use efficient algorithms
100 MB - 1 GBStream/mmap, avoid loading entirely into memory
> 1 GBStreaming 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

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Building, compiling, and resolving dependency issues across languages

The English summary is being prepared. Showing the original description.

vstorm-co/pydantic-deepagents1.1KUpdated Oct 19, 2026

Systematic code review for bugs, security, style, and performance

The English summary is being prepared. Showing the original description.

vstorm-co/pydantic-deepagents1.1KUpdated Oct 19, 2026

Review Python code for quality, security, and best practices

The English summary is being prepared. Showing the original description.

vstorm-co/pydantic-deepagents1.1KUpdated Oct 19, 2026

Comprehensive data analysis skill for CSV files using Python and pandas

The English summary is being prepared. Showing the original description.

vstorm-co/pydantic-deepagents1.1KUpdated Oct 19, 2026

Working with diverse data formats: binary, text, structured, and custom

The English summary is being prepared. Showing the original description.

vstorm-co/pydantic-deepagents1.1KUpdated Oct 19, 2026

Best practices for creating research diagrams with Excalidraw MCP tools

The English summary is being prepared. Showing the original description.

vstorm-co/pydantic-deepagents1.1KUpdated Oct 19, 2026

See all skills by vstorm-co

Report a problem with this skill