SuperAPI AI Directory

code-optimizer

Coding & development

View repository

Updated 10-16 01:19

About this skill

Code Optimizer

Task Objectives

This skill is a professional code optimization and analysis tool, designed to improve code quality through a layered, multi-dimensional, and interpretable analysis framework and to serve as a core capability for AI-assisted programming.

Core Value

  • Layered Analysis: Avoids "over-optimization" or "ineffective suggestions" by adopting a three-layer analysis funnel architecture
  • Professional Diagnosis: Based on 20 years of senior architect experience, provides precise diagnosis of code issues
  • Actionable Suggestions: Not only points out problems, but also provides specific refactoring plans and code examples
  • Tech Stack Awareness: Provides targeted optimization suggestions according to different programming languages and frameworks

Applicable Scenarios

  • Code Review
  • Refactoring legacy code
  • Performance bottleneck analysis
  • Security audit
  • Technical debt cleanup
  • Best practice guidance

Core Architecture Design: Three-Layer Analysis Funnel

┌─────────────────────────────────────────────────────────────┐
│  L1: 静态合规层 (Static Compliance)                           │
│  ├── 命名规范检查                                              │
│  ├── 注释缺失检测                                              │
│  ├── 未使用的变量/函数                                         │
│  ├── 死代码识别                                                │
│  └── 潜在语法错误                                              │
├─────────────────────────────────────────────────────────────┤
│  L2: 逻辑与结构层 (Logic & Structure)                         │
│  ├── DRY 原则:重复代码块识别                                  │
│  ├── 单一职责:函数/类长度分析                                 │
│  ├── 魔法数字/字符串:硬编码值提取                             │
│  ├── 循环复杂度:嵌套深度检测                                  │
│  └── 抽象不足:设计模式应用建议                                │
├─────────────────────────────────────────────────────────────┤
│  L3: 性能与安全层 (Performance & Security)                    │
│  ├── 时间/空间复杂度分析                                       │
│  ├── SQL 注入风险检测                                          │
│  ├── 资源泄漏:文件句柄/数据库连接                             │
│  ├── 并发竞争条件                                              │
│  └── 安全漏洞:XSS/CSRF/硬编码密钥                            │
└─────────────────────────────────────────────────────────────┘

Operating Steps

Step 1: Context Understanding

Before analyzing code, first understand the code's business scenario and usage environment:

Key Questions:

  1. What is the purpose of this code? (High-frequency trading interface vs. backend management script)
  2. What are the performance requirements? (Low latency vs. batch processing)
  3. What are the security requirements? (Public API vs. internal tool)
  4. What is the tech stack? (Python/Java/JavaScript/Go, etc.)

Step 2: Three-Layer Analysis Scan

Analyze layer by layer in the order L1 -> L2 -> L3:

  1. L1 Static Compliance Layer: Check naming conventions, comment completeness, unused code, dead code, syntax risks
  2. L2 Logic and Structure Layer: Check duplicate code, function length, magic numbers, nested loops, cyclomatic complexity
  3. L3 Performance and Security Layer: Check algorithm complexity, resource leaks, security risks, concurrency issues

Detailed detection checklist: See references/checklist.md

Step 3: Generate Optimization Report

Generate a complete report containing a problem summary, refactoring plan, and performance suggestions according to the standard format.

Report template: See references/report-template.md


Core Capabilities

1. Three-Layer Analysis Funnel

  • L1 Static Compliance: Basic syntax and best practice checks
  • L2 Logic and Structure: Code duplication, abstraction level, maintainability analysis
  • L3 Performance and Security: Performance bottlenecks, security vulnerabilities, concurrency issue detection

Detailed architecture: See references/architecture.md

2. Prompt Engineering Strategy

  • Role Setting: 20-year senior architect and code review expert
  • Chain-of-Thought Workflow: Context understanding -> three-layer scan -> report generation
  • Output Principles: Diagnose first, then suggest; reject over-engineering; maintain backward compatibility

Detailed strategy: See references/prompt-strategy.md

3. Tech Stack Awareness

Recommend corresponding toolchains based on the tech stack:

  • Python: mypy, pylint, black, pytest
  • Java: SpotBugs, SonarQube, JUnit
  • JavaScript/TypeScript: ESLint, TypeScript, Jest
  • Go: golangci-lint, pprof, testing

Full recommendations: see references/tech-stack.md


Output format specification

Issue priority definitions

Priority Label Description Response time
P0 🔴 Critical Bug/security vulnerability, must be fixed immediately Immediately
P1 🟠 Performance bottleneck/logic defect, fix as soon as possible Within 24 hours
P2 🟡 Maintainability issue, fix within the plan Next iteration
P3 🟢 Optimization suggestion, handle when there is time Technical debt

Standard report structure

  1. Overall assessment (complexity, maintainability, main risks)
  2. Issue summary (sorted by priority)
  3. Key issues and refactoring plans (including code comparisons)
  4. Performance optimization suggestions
  5. Security checklist
  6. Follow-up action plan

Full template: see references/report-template.md


Usage examples

Example 1: Python code optimization

Optimize an order processing function that contains magic numbers and is too deeply nested.

View full example: references/examples.md#example-1-python-code-optimization

Example 2: JavaScript performance optimization

Fix N+1 query issues and SQL injection vulnerabilities.

View full example: references/examples.md#example-2-javascript-performance-optimization


Advanced features

1. Interactive refactoring

Use conversational interaction: first list the detected issues, then let the user choose which issue to view detailed analysis for first.

2. Test case generation

While optimizing code, automatically generate corresponding unit tests to ensure refactoring does not break existing logic.

3. Technical debt quantification

Assess the current technical debt (in hours), and provide the debt composition and suggested priority.

Detailed description: see references/advanced-features.md


Notes

⚠️ Avoid over-optimization

  • Do not optimize prematurely: If the code is simple and efficient, do not force in complex patterns
  • Consider ROI: The benefit of optimization should outweigh the cost of investment
  • Keep it simple: Simple code is better than complex "optimized" code

✅ Best practices

  • Tests first: Ensure sufficient test coverage before refactoring
  • Small iterative steps: Refactor only a small part at a time to ensure rollback is possible
  • Code review: Important refactorings should go through team review
  • Performance baseline: Performance data should support both before and after optimization

📊 Quantitative metrics

Recommended optimization effect metrics to track:

Metric Tool Target value
Cyclomatic complexity eslint-complexity < 15
Duplication rate sonarqube < 5%
Test coverage coverage.py > 80%
Technical debt sonarqube < 5 days
Security vulnerabilities bandit/snyk 0

Resource index


Version History

Version Date Changes
v1.0.0 2026-04-11 Initial version, implementing the three-layer analysis funnel architecture

Reference Resources