Skip to content
This repository was archived by the owner on Jul 11, 2026. It is now read-only.
This repository was archived by the owner on Jul 11, 2026. It is now read-only.

[Analysis Layer] Performance Pattern Detection #7

Closed

Description

@gloomcheng

Problem Statement

AI-generated code may have performance issues:

  • N+1 queries in loops
  • Expensive operations in hot paths
  • Memory leaks from improper cleanup
  • Blocking operations on main thread

AI can't run code to detect these issues.

Proposed Solution

Static Performance Analysis

  1. Pattern Detection

    • Database calls in loops
    • Synchronous I/O in async context
    • Missing cleanup in useEffect/lifecycle hooks
    • Large array operations without streaming
  2. Integration Points

    • Run during implement validation
    • Warn before committing problematic code
  3. Project-specific Rules

    • Define custom performance patterns to detect
    • Learn from past performance issues

Success Criteria

  • Common performance anti-patterns detected
  • Warnings during implementation
  • Configurable pattern rules

🤖 Generated with Claude Code

Activity

  1. gloomcheng commented on Dec 25, 2025

    @gloomcheng
    ContributorAuthor

    ✅ Issue #7 Completed: Performance Pattern Detection

    Successfully implemented static performance anti-pattern detection system.

    What was implemented:

    1. PerformanceAnalyzer Service - Pattern-based performance analysis

      • 16 built-in anti-pattern detection rules
      • Regex-based matching with context awareness
      • Configurable severity levels (info/warning/error)
      • Custom pattern support via config file or API
      • Pattern categories: database, async, memory, rendering, computation, io, resource-leak
    2. PerformanceAnalysisHandler - MCP tool interface

      • 5 new MCP tools: performance-analyze, performance-list-patterns, performance-add-pattern, performance-disable-pattern, performance-enable-pattern
      • Detailed reporting grouped by category and severity
      • Pattern management and customization
    3. Built-in Pattern Detection - Comprehensive coverage

      • Database: N+1 queries in loops, sequential awaits
      • React/Rendering: Missing dependency arrays, missing cleanup, inline functions, missing list keys
      • Async/Await: Sync I/O in async context, unhandled promises
      • Memory: Inefficient array operations, JSON.parse in loops
      • Resource Leaks: Unclosed connections, missing event listener cleanup
      • Blocking: Sync crypto operations, catastrophic regex backtracking

    Integration:

    • Fully integrated with ImplementationValidator
    • Runs automatically as 4th priority validation check
    • Critical performance issues block implementation completion
    • Warnings provide actionable optimization suggestions

    Customization Features:

    • Add project-specific patterns via MCP tool or .cortex/performance.json
    • Disable noisy patterns without removing them
    • Override severity levels per pattern
    • File pattern matching for targeted analysis (e.g., only *.tsx files)
    • Context-aware matching (e.g., only flag in loops)

    Example Patterns Detected:

    // N+1 Query (ERROR)
    for (const user of users) {
      await db.findOne({ id: user.id }); // 🚨 Database query in loop
    }
    
    // Missing Cleanup (ERROR)
    useEffect(() => {
      window.addEventListener('resize', handleResize);
      // ❌ No cleanup function!
    }, []);
    
    // Inline Function (INFO)
    <Button onClick={() => console.log('click')} /> // ℹ️ Creates new function on every render

    Validation Flow:

    1. Danger Zones → 2. Environment → 3. Dependencies → 4. Performance → 5. Mocks → 6. Unused Code

    This completes the second Analysis Layer feature, giving AI the ability to:

    • Detect performance anti-patterns without running code ✅
    • Provide context-aware optimization suggestions ✅
    • Learn project-specific performance requirements ✅

    Committed in: 0dc2e9d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlayer:analysisAnalysis Layer - static analysis & impactpriority:mediumMedium priority item

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions