AGENT SKILL

Django/React 性能剖析与优化

performance-optimization

剖析并优化 AS v2 的性能(Django 后端 + React 前端)。适用于接口响应缓慢、请求触发 N+1 查询、打包体积增大,或 Core Web Vitals 未达标时。

License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 0
Forks
0

01 前言 Front Matter

name
performance-optimization
description
Profile and optimize AS v2 performance (Django backend + React frontend). Use when an endpoint is slow, a request fires N+1 queries, the bundle grows, or Core Web Vitals miss target.

02 资源文件 2

03 SKILL.md 正文

Performance Optimization — Aprender Sistema

Measure before optimizing. Profile first, identify the actual bottleneck, fix it, measure again. Don't scatter React.memo or select_related on a hunch.

AS v2 has active perf epics: #777 (grid phases), #866 (ACID). PR #1160 cut monthly grid p95 by -69% (phase 2).

Workflow

1. MEASURE  → Establish baseline (numbers, not feelings)
2. IDENTIFY → Find the actual bottleneck (profile, don't guess)
3. FIX      → Address that specific bottleneck
4. VERIFY   → Measure again, confirm improvement vs baseline
5. GUARD    → Add a test/monitor to prevent regression

Done when: before/after numbers are recorded, the targets below are met, and a guard exists.

Where to look

  • Backend (query profiling, N+1, indexes, aggregations, Celery, Redis cache): reference/backend.md
  • Frontend (Lighthouse, bundle analysis, re-renders, Antd, code splitting, images, caching): reference/frontend.md

Targets (CI enforced)

Backend (Django/DRF)

Metric Target Where
API p95 latency ≤ 200ms gunicorn logs
DB queries per request ≤ 10 django-debug-toolbar (dev)
Cache hit rate (Redis) ≥ 70% availability queries
Monthly grid p95 ≤ baseline −69% after #777 phase 2

Frontend (React/Vite), from v2/frontend/lighthouserc.cjs

Metric Target Severity
Lighthouse Performance ≥ 70 error (fails CI)
Lighthouse Accessibility ≥ 90 error (fails CI)
LCP ≤ 2.5s error
CLS ≤ 0.1 error
Total Blocking Time ≤ 300ms error
Initial JS bundle (gzipped) ≤ 250KB Antd is the main weight
manualChunks in vite.config none breaks dep ordering (prod crash)

Current Lighthouse: Desktop 95, Mobile 79 (mobile bottleneck = antd bundle).

Common Rationalizations

Rationalization Reality
"It's fast on my machine" Profile on prod-like conditions (docker + realistic data volume)
"Users won't notice" RUM from real users. 100ms matters.
"Framework handles perf" Django/React prevent some issues, not N+1 or bundle bloat
"We'll optimize later" Perf debt compounds. Fix N+1 and bundle issues now.
"The DB is fast enough" Check query count and duration per request

Verification

After a perf change:

  • [ ] Before/after measurements with specific numbers
  • [ ] Bottleneck identified (not guessed)
  • [ ] Core Web Vitals in target range
  • [ ] Bundle size change reviewed
  • [ ] No new N+1 queries
  • [ ] Lighthouse CI passes
  • [ ] Existing tests still pass

References

  • Epic #777: Monthly grid optimization · Epic #866: ACID/deadlock handling
  • PR #1160: Phase 2 grid p95 -69%
  • Memory: Lighthouse scores · feedback_no_manual_chunks.md · feedback_react18_fetchpriority.md

04 同仓库更多 Skills

matheusnorjosa
matheusnorjosa/aprender_sistema

技术文档写作规范

writing-standards

遵循 AS v2 技术写作规范(清晰、简洁、主动语态、Python/Django 惯例)。适用于撰写 README、文档字符串(PEP 257)、提交信息、PR 描述、错误信息或任何技术文档。

技术文档工程师技术文档编写
★ 0
matheusnorjosa
matheusnorjosa/aprender_sistema

成果验证关卡

verification-gate

在宣称成功之前先进行验证。适用于准备表示某功能可用/已完成、实现功能后、修复缺陷后,或推送代码前——先运行验证命令并确认输出。

测试工程师成果验证与价值评估
★ 0
matheusnorjosa
matheusnorjosa/aprender_sistema

测试驱动开发

test-driven-development

在 AS v2(pytest + Django/DRF)中先编写失败的测试,再进行实现。适用于实现功能或修复缺陷时,在编写任何生产代码之前使用。

测试工程师测试与质量保障
★ 0
matheusnorjosa
matheusnorjosa/aprender_sistema

子智能体编排开发

subagent-development

在 AS v2 中编排子智能体——将任务拆解为相互独立的领域,并行处理并进行两阶段审查。适用于委派探索、实现或跨文件验证,以加快工作进度并节省主上下文。

AI 工程师编码任务委派
★ 0
matheusnorjosa
matheusnorjosa/aprender_sistema

自动化安全扫描

security-scan

为 AS v2 提供自动化安全扫描。在提交前或审查变更中的漏洞时使用。执行依赖审计(pip-audit、npm audit)、密钥检测(grep 模式)和代码模式扫描(SQL 注入、XSS、eval、pickle、硬编码密钥)。与项目 hooks 系统集成。

安全工程师安全检测工程
★ 0
matheusnorjosa
matheusnorjosa/aprender_sistema

交接文档恢复工作

resume-handoff

从保存的交接文档恢复工作,在继续之前先根据当前代码库验证其状态。适用于上下文清空后或在新会话中(通过路径、会话名称或 GitHub issue)从保存的交接文档恢复工作。

软件开发工程师会话上下文交接
★ 0