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. 核心 Web 指标(Core Web Vitals)

Targets

目标值

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

When to Measure

测量时机

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

阶段工具
开发阶段Local Lighthouse
CI/CDLighthouse 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

排查结果处理方案
大型库导入特定模块
重复依赖去重、更新版本
路由代码在主包代码拆分
未使用导出摇树优化

4. Runtime Profiling

4. 运行时性能分析

Performance Tab Analysis

性能面板分析

PatternMeaning
Long tasks (>50ms)UI blocking
Many small tasksPossible batching opportunity
Layout/paintRendering bottleneck
ScriptJavaScript execution
特征表现问题含义
Long tasks (>50ms)阻塞UI
大量小任务可考虑批量处理
Layout/paint渲染瓶颈
ScriptJavaScript执行耗时

Memory Tab Analysis

内存面板分析

PatternMeaning
Growing heapPossible leak
Large retainedCheck references
Detached DOMNot cleaned up

特征表现问题含义
堆内存持续增长可能存在内存泄漏
大对象被保留检查引用关系
Detached 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数据

注意: 最快的代码是无需执行的代码。先删除冗余代码再进行优化。