Communitygithub.com

ComeOnOliver/skillshub

識別 N+1 查詢、低效迴圈、記憶體洩漏及緩慢演算法等效能瓶頸。當使用者提及效能問題、程式碼緩慢、最佳化或效能剖析時使用。

skillshub 是什麼?

此技能旨在幫助開發者與 AI 代理工具快速診斷並修正常見的程式碼效能瓶頸。它涵蓋了後端、前端、資料庫及網路等層面的問題,例如 N+1 查詢、O(n²) 複雜度的巢狀迴圈、React 中的不必要重新渲染、記憶體洩漏以及未最佳化的資源載入。技能會根據具體情境提供程式碼範例(含「錯誤」與「正確」寫法)來指導修復,並能生成結構化的效能報告,將問題依嚴重程度分級。它支援多種語言與平台(如 JavaScript、Python 及資料庫查詢),並推薦使用 Chrome DevTools、cProfile 及 EXPLAIN ANALYZE 等工具進行深入分析。整體來說,這是一個全面的效能檢查清單,遵循「先剖析再最佳化」的最佳實務,協助開發者在不破壞可讀性的前提下做出效能權衡。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/crazydubya/performance-profiler

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

效能剖析器

辨識並建議修正程式碼中常見的效能瓶頸。

使用時機

  • 使用者回報效能問題或程式碼執行緩慢
  • 最佳化需求
  • 針對效能的程式碼審查
  • 使用者提及「慢」、「瓶頸」、「最佳化」、「記憶體洩漏」

指示

1. 辨識效能反模式

N+1 查詢問題:

// 錯誤:N+1 查詢
users.forEach(user => {
  const posts = db.query('SELECT * FROM posts WHERE user_id = ?', user.id);
});

// 正確:使用 JOIN 的單一查詢
const usersWithPosts = db.query('SELECT * FROM users LEFT JOIN posts ON users.id = posts.user_id');

低效迴圈:

# 錯誤:O(n²) 巢狀迴圈
for item in list1:
    for other in list2:
        if item.id == other.id:
            process(item, other)

# 正確:使用雜湊映射達到 O(n)
lookup = {other.id: other for other in list2}
for item in list1:
    if item.id in lookup:
        process(item, lookup[item.id])

不必要的重新渲染 (React):

// 錯誤:每次渲染都建立新物件
<Component style={{ margin: 10 }} />

// 正確:在外部定義或使用 useMemo
const style = { margin: 10 };
<Component style={style} />

記憶體洩漏:

  • 未清除的事件監聽器
  • 未清除的計時器
  • 循環參考
  • 無限制的大型快取

阻塞操作:

  • 同步的檔案 I/O
  • UI 執行緒中的長時間計算
  • 缺少分頁

2. 資料庫效能

檢查項目:

  • 缺少外鍵索引
  • SELECT * 而非指定欄位
  • 迴圈中的查詢 (N+1)
  • 缺少查詢限制(LIMIT)
  • 低效的 JOIN

建議:

  • 新增索引:CREATE INDEX idx_user_id ON posts(user_id);
  • 使用預先載入/預先提取
  • 實作分頁
  • 使用資料庫查詢分析器 (EXPLAIN)

3. 演算法複雜度

辨識:

  • O(n²) 或更差的演算法
  • 重複計算
  • 不必要的排序
  • 低效的資料結構

常見修正:

  • 使用雜湊映射達到 O(1) 查詢,取代 O(n) 陣列搜尋
  • 二元搜尋 O(log n) 取代線性搜尋 O(n)
  • 記憶化處理重複計算
  • 對昂貴的操作使用惰性求值

4. 前端效能

檢查項目:

  • 大量套件體積
  • 未最佳化的圖片
  • 缺少程式碼分割
  • 低效的 React 元件
  • 缺少記憶化

建議:

  • 延遲載入:const Component = lazy(() => import('./Component'));
  • 圖片最佳化
  • 對昂貴操作進行防抖/節流
  • 長列表使用虛擬滾動
  • 大量計算使用 Web Workers

5. 網路效能

問題:

  • 過多的 HTTP 請求
  • 大量 payload
  • 缺少快取
  • 同步請求

解決方案:

  • 打包/合併資源
  • 實作壓縮 (gzip, brotli)
  • 使用 HTTP/2 多路複用
  • 新增快取標頭
  • 平行 vs 序列請求

6. 產生效能報告

效能分析
===================

嚴重問題(立即修復):
1. UserController.index 中的 N+1 查詢 (file.js:45)
   - 影響:每次請求產生 100+ 次資料庫查詢
   - 修正:使用預先載入或 JOIN

2. EventEmitter 中的記憶體洩漏 (file.js:120)
   - 影響:記憶體無限制成長
   - 修正:在清理時移除監聽器

高優先級:
3. processData 中的 O(n²) 迴圈 (file.js:200)
   - 影響:大量資料時執行緩慢
   - 修正:使用雜湊映射達到 O(n)

中優先級:
4. 缺少圖片最佳化
   - 影響:頁面載入緩慢
   - 修正:使用 next/image 或手動最佳化

7. 效能剖析工具

JavaScript:

  • Chrome DevTools 的 Performance 面板
  • Node.js --inspect 旗標
  • console.time() / console.timeEnd()

Python:

  • cProfile 模組
  • line_profiler
  • memory_profiler

資料庫:

  • EXPLAIN / EXPLAIN ANALYZE
  • 慢查詢日誌
  • pg_stat_statements (PostgreSQL)

最佳實務

  • 先剖析再最佳化
  • 專注於熱點路徑(80/20 法則)
  • 衡量變更的影響
  • 權衡可讀性與效能
  • 記錄效能關鍵區段

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能