Communitygithub.com

lguidolin/效能與規模

在處理熱門路徑、列表端點、分頁、迴圈中的資料存取或公共介面/架構時使用。徵兆包括無限制查詢、N+1 存取、無延遲預算、未經測量就最佳化,或修改許多消費者依賴的介面。關鍵字包括分頁、N+1、Hyrum定律、效能預算、打包大小。

效能與規模 是什麼?

此技能專注於系統效能與規模的原則與實務,特別適用於 AI 代理開發者處理熱門路徑、列表端點、分頁、迴圈中的資料存取或公共介面時。它強調「效能是一項有預算的功能」,必須先測量再最佳化,避免投機式最佳化。技能涵蓋設定延遲目標與客戶端預算(如打包大小),並將超出預算的回歸視為錯誤。它告誡開發者注意 N+1 資料存取模式(建議使用批次或聯結取代迴圈查詢),並預設對所有可能增長的列表實施分頁,以防止無限制結果集造成的延遲與拒絕服務風險。此外,技能引用 Hyrum 定律,提醒公共介面(如 API/架構)的每個可觀察行為都可能成為合約,應透過新增與棄用而非默默修改來演進。支援的平台包括 GraphQL 層(如使用 look-ahead/DataLoader)與 CI 中的預算檢查(如打包大小限制、查詢成本限制)。整體而言,此技能幫助開發者建立可規模化的系統,避免常見的效能陷阱。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/performance-and-scale

在你喜歡的 AI 中提問

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

說明文件

效能與規模 是做什麼的?

概述

效能是一項有預算的功能。測量它、限制它,並記住今天的行為會成為明天的合約。系統很少因為你設計的吞吐量而崩潰——它們崩潰在你沒有建立索引的查詢,以及你沒有分頁的列表上。

原則

  • 設定預算並據此測量。 延遲目標(與 observability-and-slos 的 SLO 相關)和客戶端預算(例如打包大小)。超出預算的回歸即為錯誤。
  • 先測量再最佳化。 在修改程式碼之前,先用資料找出真正的瓶頸——分析報告、查詢計畫、追蹤。沒有投機式最佳化。
  • 預設分頁。 任何可能增長的列表都應以設有上限的頁面大小進行分頁。無限制的結果集會造成延遲與拒絕服務的風險。
  • 留意 N+1 存取模式。 在迴圈中擷取資料是最常見的規模化失敗原因;應改用批次或聯結。(在此技術棧上:使用 GraphQL 層的 look-ahead/DataLoader,而非逐行解析。)
  • Hyrum 定律是真實存在的:介面的每個可觀察行為,一旦有足夠多的消費者,就會變成某人依賴的合約——包括你從未意圖的行為(排序、可空性、錯誤形狀、時序)。將公共介面(特別是 API/架構)視為合約:新增與棄用,不要默默修改。 graphql-contract-testing 的合約測試固定了你選擇的行為;紀律則保護那些你未選擇的行為。

快速參考

氣味修正方式
迴圈內有查詢批次或聯結;使用 look-ahead
無限制的列表端點加入有上限的分頁
「讓我最佳化這個」但未經測量先分析;找出真正的瓶頸
修改欄位的型別/可空性/順序這是合約變更——新增新的,棄用舊的
沒有延遲或打包目標設定預算;將回歸視為錯誤

強制執行: 可在 CI 中機械化檢查的預算(打包大小限制、查詢成本限制);分頁與 N+1 的避免則仰賴審查者的判斷,並輔以負載測試與查詢計畫審查。

完整理由:憲法第十一條,收錄於 engineering-constitution/references/engineering-constitution.md。

Individual skills in this repo

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

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/cloud-delivery-aks

Use when deploying to Kubernetes or Azure Kubernetes Service (AKS), configuring cloud secrets, setting up progressive rollout/canary, per-PR ephemeral environments, or k8s health probes. Keywords — Kubernetes, AKS, Key Vault, Argo Rollouts, Flagger, canary, blue-green, liveness, readiness, PodDisruptionBudget, HPA, rollback, GHCR.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/defense-in-depth-security

Use when handling untrusted input, secrets, authentication/authorization, or dependencies — or threat-modeling a new surface. Keywords — STRIDE, threat model, least privilege, secrets management, supply chain, dependency scanning, input validation, audit log, defense in depth.

lguidolin/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/init-repo-CI

Use when setting up a new repository with conventional commits, release-please, and CI automation, or when retrofitting an existing repository that lacks automated versioning and PR validation workflows.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/merge-gates-and-automation

Use when setting up or changing CI, pre-push hooks, or a task runner, or deciding what must pass before merge. Symptoms — tempted to put authoritative checks only in a local hook, skip CI, bypass with --no-verify, or unsure what gates a merge vs. runs locally.

lguidolin/observability-and-slos

Use when adding logging, metrics, tracing, health checks, SLOs, or alerting — or when building a service surface that needs to be operable and debuggable. Keywords — structured logs, OpenTelemetry, correlation id, RED metrics, liveness, readiness, SLI, SLO, error budget, alerting.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相關技能