npx agentspec-cli install e419f284-1ed7-42f7-be87-45a374d69890 --file-type cursor-rules→ .cursor/rules/
---
description:
globs:
alwaysApply: false
---
**Global Rule: Performance Optimization Reminders (Template)**
**Purpose:** To encourage the AI to consider and suggest performance-efficient solutions, highlight potential bottlenecks, and promote best practices for writing performant code, without encouraging premature optimization.
**Instructions for the AI:**
"When generating, reviewing, or suggesting code, actively consider its performance implications. Balance performance with clarity and maintainability. If a less performant but significantly clearer solution is chosen, this might be acceptable, but potential performance trade-offs should be noted if relevant. Always prioritize profiling before heavy optimization."
**1. General Principles:**
* "**Profile First:** Before suggesting complex optimizations, emphasize or ask about profiling to identify actual bottlenecks. Avoid premature optimization on non-critical code paths."
* "**Clarity and Maintainability:** Performance improvements should not come at an extreme cost to code readability or maintainability unless absolutely necessary and justified for a critical bottleneck."
* "**Context Matters:** The importance of performance varies. For performance-critical sections (e.g., inner loops, high-throughput systems), apply more scrutiny. For less critical sections, prioritize simplicity."
**2. Algorithmic Efficiency:**
* "When choosing algorithms, be mindful of their time and space complexity (Big O notation). Suggest more efficient algorithms where appropriate and the trade-offs are favorable."
* "For common tasks (sorting, searching, etc.), prefer a_lgorithms provided by the standard library, as they are typically well-optimized."
**3. Data Structure Selection:**
* "Recommend data structures appropriate for the intended operations (e.g., `std::unordered_map` or `dict` for fast lookups, `std::vector` or `list` for sequences with different insertion/access patterns). Explain the performance characteristics."
**4. Memory Management & Allocations (General, can be more specific in language rules):**
* "Suggest strategies to minimize unnecessary memory allocations and deallocations, especially in loops or performance-sensitive code."
* "Consider object pooling or arena allocation for scenarios with many short-lived objects, if appropriate for the language and context."
* "Be mindful of data locality and cache utilization when processing large data sets."
**5. I/O Operations:**
* "Highlight that I/O operations (disk, network) are often major bottlenecks."
* "Suggest batching I/O operations where possible (e.g., reading/writing larger chunks of data at once)."
* "Recommend asynchronous I/O for non-blocking operations, especially in applications requiring high concurrency, if idiomatic for the language/framework."
* "Advise closing resources (files, network connections) promptly."
**6. Concurrency and Parallelism:**
* "If the task can be parallelized and the environment supports it, suggest potential concurrency or parallelism strategies (e.g., multi-threading, async/await patterns, parallel algorithms)."
* "Also, point out the complexities involved, such as synchronization, race conditions, and deadlocks."
**7. Language-Specific Optimizations:**
* "(User to add general prompts for language-specific considerations, which can be detailed further in language-specific rules. Examples:)
* **C++:** 'Consider move semantics, `constexpr` for compile-time computation, inlining, or specific compiler optimizations where relevant.'
* **Python:** 'Be mindful of the Global Interpreter Lock (GIL) for CPU-bound multi-threading. Suggest multiprocessing or C extensions for true parallelism. Use efficient built-in functions and list comprehensions.'
* **JavaScript:** 'Minimize DOM manipulations. Be aware of an_d optimize for the JavaScript engine's handling of objects and arrays. Consider tree shaking and code splitting for frontend assets.'
* **Java:** 'Consider JIT compilation effects, heap tuning, and efficient use of the garbage collector. Be mindful of boxing/unboxing overhead.'"
**8. Lazy Evaluation/Loading:**
* "Suggest lazy loading of resources or lazy evaluation of computations where appropriate to improve startup time or reduce unnecessary work."
**9. Caching:**
* "Where applicable, suggest caching frequently accessed or computationally expensive data. Discuss cache invalidation strategies."
**10. Query Optimization (for database interactions):**
* "When generating or discussing database queries:
* Recommend using appropriate indexes.
* Suggest fetching only necessary columns (`SELECT col1, col2` instead of `SELECT *`).
* Advise against N+1 query problems in ORMs or data access layers."
"When suggesting a significant code structure or algorithm, briefly comment on its performance characteristics or potential trade-offs."Ai Sdk Cpp Configuration
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Performance Rules
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Performance Rules
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Cachekit Configuration
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
Sign in to leave a comment.