performant-code

Solid

Writing efficient code that handles large data and tight constraints

AI & Automation 859 stars 98 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 96/100

Stars 20%
98
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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 `nu...

Details

Author
vstorm-co
Repository
vstorm-co/pydantic-deepagents
Created
6 months ago
Last Updated
yesterday
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category