Communitygithub.com

lguidolin/性能与规模

用于处理热点路径、列表端点、分页、循环中的数据访问或公共接口/模式。症状包括——无界查询、N+1 访问、无延迟预算、未测量就优化、或修改多个消费者依赖的接口。

性能与规模 是什么?

该技能(`performance-and-scale`)专注于在 AI 辅助编码(如 Claude Code、Cursor)中指导开发者构建可扩展且高性能的系统。它强调将性能视为一项有预算的特性,要求开发者设定延迟和客户端(如包体积)预算,并通过持续测量来防止回归。技能的核心原则包括:在优化前进行测量(通过分析、查询计划等数据发现真正瓶颈)、默认对可能增长的列表进行分页、警惕循环中的数据获取(N+1 问题,建议使用批处理或 GraphQL 层的 DataLoader),并尊重 Hyrum 定律——即任何可观察到的接口行为一旦被消费者依赖就会成为契约,因此应使用添加和弃用策略而非静默修改。该技能适用于所有主要 AI 编码平台,并提供了快速参考表用于识别常见性能“味道”及对应的修复措施,同时强调在 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)和客户端预算(例如包体积)。回归超出预算即为缺陷。
  • 先测量,再优化。 在修改代码前,通过数据(Profile、查询计划、追踪)找到真正的瓶颈。杜绝推测性优化。
  • 默认分页。 任何可能增长的列表都应分页,并设置分页大小上限。无界的结果集是延迟和拒绝服务攻击的隐患。
  • 警惕 N+1 访问模式。 在循环中获取数据是最常见的可扩展性故障;应改用批处理或连接查询。(在此技术栈上:使用 GraphQL 层的 Look-ahead/DataLoader 而非逐行解析。)
  • 海勒姆定律是真实的:接口的每个可观察行为一旦有足够多的消费者,就会成为某人依赖的契约——包括你从未意图的行为(顺序、可空性、错误形态、时序)。请将公共接口(尤其是 API/模式)视为契约:添加并弃用,勿静默修改。 graphql-contract-testing 的契约测试固定了你选择的行为;自律保护了你未选择的行为。

快速参考

问题现象修复方法
循环内的查询批处理或连接查询;使用 Look-ahead
无限制的列表端点添加分页上限
“让我优化这个”但未测量先 Profile,找到真正的瓶颈
修改字段的类型/可空性/顺序这是契约变更——新增字段,弃用旧字段
无延迟或包体积目标设定预算;将回归视为缺陷

执行机制: 预算在 CI 中进行可机械化检查(包体积限制、查询成本限制);分页和 N+1 避免由评审人员根据负载测试和查询计划审查做出判断。

完整理由:宪法第 XI 条,附在 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.

相关技能