agent-skills / accelint-ts-performance
AGENTS.md25 starsChanged 54 days agoApache-2.0View on GitHub
Comprehensive performance optimization guide for JavaScript and TypeScript applications, designed for AI agents and LLMs. Each rule includes one-line summaries here, with links to detailed examples in the references/ folder. Load reference files only when you need detailed implementation guidance for a specific rule. This structure minimizes context usage while providing complete implementation guidance when needed. NEVER do these - they appear in codebases frequently but significantly degrade performance: Note: For general best practices (type safety with any/enum, avoiding null,…
We split this AGENTS.md into the rules it gives an agent
9 rules. About 0 are common, 6 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
NEVER: do these - they appear in codebases frequently but significantly degrade performance:
- Very specific: line 24
NEVER: use Array.includes() for repeated lookups - O(n) linear search.
- Distinctive: line 27
NEVER: create unbounded loops or queues - prevents runaway resource consumption.
- Very specific: line 28
NEVER: place try/catch in hot paths - V8 cannot inline functions with try-catch (3-5x slowdown).
- Distinctive: line 49
Use table lookups instead of conditionals for static values.
- Distinctive: line 106
Write cache-friendly code with sequential access patterns.
- Distinctive: line 109
Write code with clear execution paths.
- Very specific: line 166
Profile before optimizing: - Use Chrome DevTools (browser) or node --prof (Node.js).
- Distinctive: line 169
Correctness is mandatory: - Run tests before and after.
≈ “Common” is an estimate: at least 1 in 5 of the 36,368 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
TypeScript Performance Optimization
Abstract
Comprehensive performance optimization guide for JavaScript and TypeScript applications, designed for AI agents and LLMs. Each rule includes one-line summaries here, with links to detailed examples in the references/ folder. Load reference files only when you need detailed implementation guidance for a specific rule.
How to Use This Guide
- Start here: Scan the rule summaries to identify relevant optimizations
- Load references as needed: Click through to detailed examples only when implementing
- Progressive loading: Each reference file is self-contained with ❌/✅ examples
This structure minimizes context usage while providing complete implementation guidance when needed.
Critical Performance Anti-Patterns
NEVER do these - they appear in codebases frequently but significantly degrade performance:
- NEVER chain array methods (.filter().map().reduce()) - creates intermediate arrays and multiple iterations; use single
reducepass (2-5x faster) - NEVER use
Array.includes()for repeated lookups - O(n) linear search; useSet.has()instead for O(1) hash lookup (10-100x faster) - NEVER await before checking if you need the result - suspends execution unnecessarily; defer
awaitinto branches that actually use the value - NEVER recompute constants inside loops - wastes CPU in every iteration; hoist invariants outside loops or curry functions to precompute
- NEVER create unbounded loops or queues - prevents runaway resource consumption; set explicit limits to prevent DoS and crashes
- NEVER place
try/catchin hot paths - V8 cannot inline functions with try-catch (3-5x slowdown); validate inputs before loops
Note: For general best practices (type safety with any/enum, avoiding null, not mutating parameters), use the accelint-ts-best-practices skill instead.
See individual reference files for detailed alternatives and ✅ correct patterns.
Performance Optimization Categories
Before optimizing: Profile first to identify actual bottlenecks. Premature optimization wastes effort on code that doesn't impact user experience.
Design for performance from the start. Optimize slowest resources first: network >> disk >> memory >> cpu
1. Algorithmic Optimization (10-1000x speedup)
Fix algorithmic complexity before applying micro-optimizations. O(n²) → O(n) provides orders of magnitude improvement.
1.1 Reduce Branching
Use table lookups instead of conditionals for static values; hoist invariants out of conditionals; use early returns. View detailed examples
1.2 Reduce Looping
Combine .filter().map() into single reduce pass; use Set.has() over Array.includes() for 10-50x speedup (O(1) vs O(n)); build lookups once.
View detailed examples
2. Caching & Memoization (2-100x speedup)
Cache expensive computations and avoid repeated work. Trade memory for CPU when computation cost justifies it.
2.1 Memoization
Hoist loop-invariant code; precompute constants at module load; memoize pure functions with limited input domain; avoid memoizing trivial computations. View detailed examples
2.2 Cache Property Access
Cache property lookups before loops; eliminate single-use aliases; avoid unnecessary destructuring; cache array.length. View detailed examples
2.3 Cache Storage API Calls
Cache localStorage, sessionStorage, and document.cookie reads in memory; avoid repeated JSON.parse on same data.
View detailed examples
3. I/O Optimization (2-50x speedup)
Batch operations, parallelize independent work, defer blocking operations.
3.1 Batching
Batch operations to amortize costly processes, especially for I/O-bound operations (network requests, database queries, file writes). View detailed examples
3.2 Defer Await
Move await into branches where result is actually used; parallelize independent async operations; avoid blocking on I/O that could be deferred.
View detailed examples
4. Memory & Allocation (1.5-5x speedup)
Reduce garbage collection pressure and object creation in hot paths.
4.1 Object Operations
Mutate when safe (local scope, not returned/exposed); use shallow clones when needed; preallocate object shapes for V8 hidden classes. View detailed examples
4.2 Avoid Needless Allocations
Inline simple computations; avoid intermediate variables in hot paths; reduce GC pressure by reusing objects when possible. View detailed examples
5. Memory Locality (1.5-3x speedup)
Write cache-friendly code with sequential access patterns.
5.1 Predictable Execution and Cache Locality
Write code with clear execution paths; use sequential memory access; group related data; prefer Array of Structs for sequential processing. View detailed examples
6. Safety & Bounds (DoS prevention)
Prevent runaway resource consumption and denial-of-service scenarios.
6.1 Bounded Iteration
Set limits on all loops, queues, and data structures; prevent unbounded recursion; validate iteration counts from user input. View detailed examples
7. Micro-optimizations (1.05-2x speedup)
Apply in hot paths only (>1000 executions/sec). Profile first to ensure impact justifies complexity.
7.1 Currying and Partial Application
Curry functions to precompute constant parameters; reduce repeated work in loops and hot paths; optimize function call overhead. View detailed examples
7.2 Additional Performance Concerns
Batch string operations; compile regex once; avoid async overhead for synchronous code; minimize closure scope; avoid try/catch in hot paths. View detailed examples
Quick Reference for Bottleneck Mapping
For systematic bottleneck identification and categorization, load references/quick-reference.md which provides:
- Bottleneck symptom → Category mapping
- Profiler output → Optimization category lookup
- Anti-pattern detection with concrete code examples
- Decision matrix for when to optimize
Optimization Impact Summary
| Category | Typical Speedup | When to Apply |
| Algorithmic (O(n²) → O(n)) | 10-1000x | Always fix first |
| Caching & Memoization | 2-100x | Repeated expensive computations |
| I/O Optimization | 2-50x | Network, disk, async operations |
| Allocation Reduction | 1.5-5x | Hot paths with GC pressure |
| Memory Locality | 1.5-3x | Large datasets, sequential processing |
| Bounded Execution | Prevents DoS | All user-controlled iterations |
| Micro-optimizations | 1.05-2x | Hot paths only, after profiling |
Priority order: Fix algorithm first, then cache, then I/O, then allocations, then micro-optimize hot paths.
Important Notes
- Profile before optimizing - Use Chrome DevTools (browser) or
node --prof(Node.js). Target functions consuming >5% runtime. - Hot path definition - Code executed >1000 times per user interaction or >100 times per second in server contexts.
- Real-time systems - For 60fps rendering (16.67ms frame budget), even 1.05x improvements in critical paths matter. Profile with frame timing.
- Correctness is mandatory - Run tests before and after. Performance bugs are still bugs.
- Memory vs CPU trade-offs - Caching trades memory for speed. Monitor memory usage in production.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 28,693 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/accelint-design-foundation/AGENTS.mdAGENTS.md
- skills/accelint-eval-architect/AGENTS.mdAGENTS.md
- skills/accelint-nextjs-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-prompt-manager/AGENTS.mdAGENTS.md
- skills/accelint-react-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-react-testing/AGENTS.mdAGENTS.md
- skills/accelint-readme-writer/AGENTS.mdAGENTS.md
- skills/accelint-security-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-skill-manager/AGENTS.mdAGENTS.md
- skills/accelint-skill-manager/references/agents.mdAGENTS.md
- skills/accelint-ts-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-ts-documentation/AGENTS.mdAGENTS.md
- skills/accelint-ts-testing/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- accelint-ac-to-playwrightSkill
- accelint-architecture-docSkill
- accelint-archive-synthesisSkill
- accelint-design-foundationSkill
- accelint-english-managerSkill
- accelint-eval-architectSkill
- accelint-nextjs-best-practicesSkill
- accelint-onboard-agentsSkill
- accelint-onboard-openspecSkill
- accelint-persona-reviewSkill
- accelint-prompt-managerSkill
- accelint-qrspi-applySkill
- accelint-qrspi-archiveSkill
- accelint-qrspi-proposeSkill
- accelint-react-best-practicesSkill
- accelint-react-testingSkill
- accelint-readme-writerSkill
- accelint-security-best-practicesSkill
- referencesSkill
- accelint-skill-managerSkill
- accelint-skill-proseSkill
- accelint-tanstack-query-best-practicesSkill
- accelint-ts-audit-allSkill
- accelint-ts-best-practicesSkill
- accelint-ts-documentationSkill
- accelint-ts-performanceSkill
- accelint-ts-testingSkill
- constraints-extractorSkill
- context-driftSkill
- epistemic-mapperSkill
- generate-docsSkill
- jargon-extractorSkill
- pr-descriptionSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

