performance-profiling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Performance Profiling

性能分析

Measure, analyze, optimize - in that order.
按照测量、分析、优化的顺序进行。

🔧 Runtime Scripts

🔧 运行时脚本

Execute these for automated profiling:
ScriptPurposeUsage
scripts/lighthouse_audit.py
Lighthouse performance audit
python scripts/lighthouse_audit.py https://example.com

执行以下脚本以进行自动化分析:
脚本用途使用方法
scripts/lighthouse_audit.py
Lighthouse性能审计
python scripts/lighthouse_audit.py https://example.com

1. Core Web Vitals

1. Core Web Vitals(核心网页指标)

Targets

指标目标

MetricGoodPoorMeasures
LCP< 2.5s> 4.0sLoading
INP< 200ms> 500msInteractivity
CLS< 0.1> 0.25Stability
指标良好标准较差标准衡量维度
LCP< 2.5秒> 4.0秒加载性能
INP< 200毫秒> 500毫秒交互性能
CLS< 0.1> 0.25视觉稳定性

When to Measure

测量时机

StageTool
DevelopmentLocal Lighthouse
CI/CDLighthouse CI
ProductionRUM (Real User Monitoring)

阶段工具
开发阶段本地Lighthouse
CI/CD阶段Lighthouse CI
生产环境RUM(真实用户监控)

2. Profiling Workflow

2. 分析工作流

The 4-Step Process

四步流程

1. BASELINE → Measure current state
2. IDENTIFY → Find the bottleneck
3. FIX → Make targeted change
4. VALIDATE → Confirm improvement
1. 基准测试 → 测量当前状态
2. 定位问题 → 找到性能瓶颈
3. 修复优化 → 做出针对性修改
4. 验证效果 → 确认优化提升

Profiling Tool Selection

分析工具选择

ProblemTool
Page loadLighthouse
Bundle sizeBundle analyzer
RuntimeDevTools Performance
MemoryDevTools Memory
NetworkDevTools Network

问题场景工具
页面加载Lighthouse
包体积包分析器(Bundle analyzer)
运行时性能DevTools Performance面板
内存问题DevTools Memory面板
网络问题DevTools Network面板

3. Bundle Analysis

3. 包体积分析

What to Look For

关注要点

IssueIndicator
Large dependenciesTop of bundle
Duplicate codeMultiple chunks
Unused codeLow coverage
Missing splitsSingle large chunk
问题识别指标
大型依赖包体积排名靠前
重复代码多个代码块重复
未使用代码代码覆盖率低
缺少代码分割单个大体积代码块

Optimization Actions

优化措施

FindingAction
Big libraryImport specific modules
Duplicate depsDedupe, update versions
Route in mainCode split
Unused exportsTree shake

发现问题优化动作
大型库导入特定模块
重复依赖去重、更新版本
路由代码在主包中代码分割
未使用导出摇树优化(Tree shake)

4. Runtime Profiling

4. 运行时分析

Performance Tab Analysis

Performance面板分析

PatternMeaning
Long tasks (>50ms)UI blocking
Many small tasksPossible batching opportunity
Layout/paintRendering bottleneck
ScriptJavaScript execution
模式含义
长任务(>50ms)阻塞UI
大量小任务存在批量处理的可能
布局/重绘渲染瓶颈
脚本执行JavaScript执行耗时

Memory Tab Analysis

Memory面板分析

PatternMeaning
Growing heapPossible leak
Large retainedCheck references
Detached DOMNot cleaned up

模式含义
堆内存持续增长可能存在内存泄漏
大体积保留对象检查引用关系
分离DOM节点未被正确清理

5. Common Bottlenecks

5. 常见瓶颈

By Symptom

按症状分类

SymptomLikely Cause
Slow initial loadLarge JS, render blocking
Slow interactionsHeavy event handlers
Jank during scrollLayout thrashing
Growing memoryLeaks, retained refs

症状可能原因
初始加载缓慢大型JS文件、渲染阻塞资源
交互响应缓慢繁重的事件处理器
滚动时卡顿布局抖动
内存持续增长内存泄漏、未释放引用

6. Quick Win Priorities

6. 快速优化优先级

PriorityActionImpact
1Enable compressionHigh
2Lazy load imagesHigh
3Code split routesHigh
4Cache static assetsMedium
5Optimize imagesMedium

优先级优化动作影响程度
1启用压缩
2图片懒加载
3路由代码分割
4静态资源缓存
5图片优化

7. Anti-Patterns

7. 反模式

❌ Don't✅ Do
Guess at problemsProfile first
Micro-optimizeFix biggest issue
Optimize earlyOptimize when needed
Ignore real usersUse RUM data

Remember: The fastest code is code that doesn't run. Remove before optimizing.
❌ 不要做✅ 应该做
猜测问题先进行分析
微优化优先解决最大的问题
过早优化需要时再优化
忽略真实用户数据使用RUM数据

记住: 最快的代码是不执行的代码。优化前先考虑移除冗余代码。