sagarithm-kit / rules
Cursor rule17 starsChanged 12 days agoApache-2.0View on GitHub
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,183 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 repository252 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/ai-systems-and-rag.mdcCursor rule
- .cursor/rules/architecture-spec-driven-development.mdcCursor rule
- .cursor/rules/architecture-system-design.mdcCursor rule
- .cursor/rules/backend-distributed-systems.mdcCursor rule
- .cursor/rules/database-architecture-and-modeling.mdcCursor rule
- .cursor/rules/delivery-shipping-and-launch.mdcCursor rule
- .cursor/rules/devops-sre-observability.mdcCursor rule
- .cursor/rules/documentation-architectural-decision-records.mdcCursor rule
- .cursor/rules/engineering-ai-data-remediation-engineer.mdcCursor rule
- .cursor/rules/engineering-ai-engineer.mdcCursor rule
- .cursor/rules/engineering-api-platform-engineer.mdcCursor rule
- .cursor/rules/engineering-autonomous-optimization-architect.mdcCursor rule
- .cursor/rules/engineering-backend-architect.mdcCursor rule
- .cursor/rules/engineering-cms-developer.mdcCursor rule
- .cursor/rules/engineering-codebase-onboarding-engineer.mdcCursor rule
- .cursor/rules/engineering-code-reviewer.mdcCursor rule
- .cursor/rules/engineering-database-optimizer.mdcCursor rule
- .cursor/rules/engineering-data-engineer.mdcCursor rule
- .cursor/rules/engineering-desktop-app-engineer.mdcCursor rule
- .cursor/rules/engineering-devops-automator.mdcCursor rule
- .cursor/rules/engineering-drupal-performance.mdcCursor rule
- .cursor/rules/engineering-drupal-shopping-cart.mdcCursor rule
- .cursor/rules/engineering-email-intelligence-engineer.mdcCursor rule
- .cursor/rules/engineering-embedded-firmware-engineer.mdcCursor rule
- .cursor/rules/engineering-feishu-integration-developer.mdcCursor rule
- .cursor/rules/engineering-filament-optimization-specialist.mdcCursor rule
- .cursor/rules/engineering-finops-engineer.mdcCursor rule
- .cursor/rules/engineering-frontend-developer.mdcCursor rule
- .cursor/rules/engineering-git-workflow-master.mdcCursor rule
- .cursor/rules/engineering-i18n-engineer.mdcCursor rule
- .cursor/rules/engineering-identity-access-engineer.mdcCursor rule
- .cursor/rules/engineering-incident-response-commander.mdcCursor rule
- .cursor/rules/engineering-it-service-manager.mdcCursor rule
- .cursor/rules/engineering-minimal-change-engineer.mdcCursor rule
- .cursor/rules/engineering-mobile-app-builder.mdcCursor rule
- .cursor/rules/engineering-mobile-release-engineer.mdcCursor rule
- .cursor/rules/engineering-multi-agent-systems-architect.mdcCursor rule
- .cursor/rules/engineering-network-engineer.mdcCursor rule
- .cursor/rules/engineering-orgscript-engineer.mdcCursor rule
- .cursor/rules/engineering-payments-billing-engineer.mdcCursor rule
- .cursor/rules/engineering-prompt-engineer.mdcCursor rule
- .cursor/rules/engineering-rapid-prototyper.mdcCursor rule
- .cursor/rules/engineering-realtime-collaboration-engineer.mdcCursor rule
- .cursor/rules/engineering-search-relevance-engineer.mdcCursor rule
- .cursor/rules/engineering-section-508-specialist.mdcCursor rule
- .cursor/rules/engineering-senior-developer.mdcCursor rule
- .cursor/rules/engineering-software-architect.mdcCursor rule
- .cursor/rules/engineering-solidity-smart-contract-engineer.mdcCursor rule
- .cursor/rules/engineering-sre.mdcCursor rule
- .cursor/rules/engineering-technical-writer.mdcCursor rule
- .cursor/rules/engineering-uswds-developer.mdcCursor rule
- .cursor/rules/engineering-video-streaming-engineer.mdcCursor rule
- .cursor/rules/engineering-voice-ai-integration-engineer.mdcCursor rule
- .cursor/rules/engineering-webassembly-engineer.mdcCursor rule
- .cursor/rules/engineering-wechat-mini-program-developer.mdcCursor rule
- .cursor/rules/engineering-wordpress-performance.mdcCursor rule
- .cursor/rules/engineering-wordpress-shopping-cart.mdcCursor rule
- The first 60 shown.
The file
We split this performance-profiling-and-optimization.mdc into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Empirical Benchmarks First: Never optimize speculatively.
- Very specific: line 28
Stream Large Datasets: Never load gigabyte-scale datasets or large files into a single in-memory array (fs.readFileSync).
- Very specific: line 33
Dangling Event Listeners: Always call removeListener() / abortSignal.removeEventListener() when tearing down objects.
- Distinctive: line 34
Unbounded In-Memory Caches: Never use raw JavaScript objects or unbounded arrays as caches.
- Distinctive: line 35
Closures Retaining Large Outer Scopes: Avoid capturing large buffers or DOM trees inside long-lived callback closures.
- Very specific: line 39
Payload Compression: Ensure HTTP compression (brotli, gzip) is enabled on all responses over $1\text{KB}$.
- Very specific: line 40
Bundle Splitting & Tree-Shaking: Use dynamic import() for heavy client-side dependencies (charts, syntax highlighters, PDF generators) to …
≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule 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
<!-- SAGARITHM:START - DO NOT EDIT DIRECTLY -->
---
description: "Diagnose and eliminate performance bottlenecks, CPU hotspots, memory leaks, event-loop lag, and sub-optimal algorithmic complexity."
globs: ["**/*"]
alwaysApply: false
---
# Systems Performance & Profiling Engineering
# Systems Performance & Profiling Engineering
## Overview
This skill embodies the rigor of a Staff Performance Engineer and Systems Profiling Specialist. It provides deterministic methodologies for identifying latency bottlenecks, eliminating $O(N^2)$ algorithmic traps, and preventing memory leaks before they manifest in production.
## 🎯 Token Conservation & High-Yield Heuristics
1. **Empirical Benchmarks First**: Never optimize speculatively. Always obtain a baseline metric before refactoring (`console.time`, `process.hrtime`, or `Benchmark.js`) and demonstrate statistically significant improvement ($p < 0.05$).
2. **Minimal Diff Footprint**: Performance optimizations must target only hot inner loops identified by profiling. Avoid broad rewrites that increase regression blast radius.
## 📐 Core Engineering Directives
### 1. Algorithmic Complexity Governance
- **Eliminate $O(N^2)$ Nested Loops**: Replace nested loop searches (`array.filter(a => otherArray.some(b => b.id === a.id))`) with $O(1)$ Hash Map / `Set` lookups:
```typescript
// Convert lookup list to Set for O(1) membership testing
const validIds = new Set(otherArray.map(b => b.id));
const filtered = array.filter(a => validIds.has(a.id)); // O(N + M) vs O(N * M)
```
- **Stream Large Datasets**: Never load gigabyte-scale datasets or large files into a single in-memory array (`fs.readFileSync`). Use Node.js Streams (`fs.createReadStream`, `stream/promises`, or pipeline transforms) to process records with bounded $O(1)$ memory usage.
### 2. Runtime Profiling & Memory Leak Detection
- **Event-Loop Lag**: In Node.js, long-running synchronous operations block the event loop, stalling all concurrent HTTP requests. Break long-running CPU loops into chunks using `setImmediate()` or worker threads (`node:worker_threads`).
- **Memory Leak Patterns**:
- **Dangling Event Listeners**: Always call `removeListener()` / `abortSignal.removeEventListener()` when tearing down objects.
- **Unbounded In-Memory Caches**: Never use raw JavaScript objects or unbounded arrays as caches. Always enforce an explicit Maximum Size and Least-Recently-Used (LRU) eviction policy.
- **Closures Retaining Large Outer Scopes**: Avoid capturing large buffers or DOM trees inside long-lived callback closures.
- **Heap Snapshot Diagnostics**: Compare baseline heap snapshots with post-load snapshots to detect retained detached objects.
### 3. Network & Payload Optimization
- **Payload Compression**: Ensure HTTP compression (`brotli`, `gzip`) is enabled on all responses over $1\text{KB}$.
- **Bundle Splitting & Tree-Shaking**: Use dynamic `import()` for heavy client-side dependencies (charts, syntax highlighters, PDF generators) to keep initial JavaScript bundles under $150\text{KB}$ gzipped.
- **HTTP Caching Directives**: Set deterministic `Cache-Control` headers:
- Static hashed assets (`main.[hash].js`): `public, max-age=31536000, immutable`.
- Dynamic API responses: `private, no-cache, must-revalidate` or `stale-while-revalidate`.
## 🛑 Anti-Rationalization Matrix
| Agent Excuse / Shortcut | Performance Reality | Mandatory Action |
|---|---|---|
| *"Premature optimization is the root of all evil, so I didn't optimize this nested loop."* | Writing $O(N^2)$ operations where an $O(N)$ map lookup is natural is not avoiding premature optimization; it is gross inefficiency that crashes servers when dataset sizes grow. | Use Sets and Maps for associative lookups as standard practice. |
| *"I'll just read the whole 500MB file into memory with `readFileSync`."* | Exhausts Node.js heap limit (`ERR_STRING_TOO_LONG` or V8 OOM crash) and starves system memory. | Use streaming pipelines (`createReadStream` with readline or transform streams). |
| *"I made changes that should feel much faster."* | Speculative assertion. Perceived speed is subjective and often illusory. | Measure execution duration with microsecond precision before and after changes. |
| *"I'll store user sessions in an in-memory object."* | Unbounded memory growth, leaks memory on disconnected clients, and fails multi-instance horizontal scaling. | Store state in a bounded external store (Redis) with explicit TTL expiration. |
## ✅ Performance Verification Checklist
- [ ] No $O(N^2)$ complexity in loops processing dynamic user collections.
- [ ] File and network operations use streaming for payloads $> 10\text{MB}$.
- [ ] All caches enforce bounded capacity with LRU eviction and TTL.
- [ ] Event listeners and timeouts are cleaned up on teardown.
- [ ] Empirical execution time benchmarks confirm zero regressions.
<!-- SAGARITHM:END -->
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.

