expo-react-native-performance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExpo React Native Performance Best Practices
Expo React Native性能优化最佳实践
Comprehensive performance optimization guide for Expo React Native applications. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
这是一份针对Expo React Native应用的全面性能优化指南,包含8个类别共42条规则,按影响优先级排序,可指导自动化重构和代码生成。
When to Apply
适用场景
Reference these guidelines when:
- Writing new React Native components or screens
- Implementing lists with FlatList or FlashList
- Adding animations or transitions
- Optimizing images and asset loading
- Reviewing code for performance issues
在以下场景中参考本指南:
- 编写新的React Native组件或页面
- 使用FlatList或FlashList实现列表
- 添加动画或过渡效果
- 优化图片与资源加载
- 审查代码以排查性能问题
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | App Startup & Bundle Size | CRITICAL | |
| 2 | List Virtualization | CRITICAL | |
| 3 | Re-render Optimization | HIGH | |
| 4 | Animation Performance | HIGH | |
| 5 | Image & Asset Loading | MEDIUM-HIGH | |
| 6 | Memory Management | MEDIUM | |
| 7 | Async & Data Fetching | MEDIUM | |
| 8 | Platform Optimizations | LOW-MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 应用启动与包体积 | 关键 | |
| 2 | 列表虚拟化 | 关键 | |
| 3 | 重渲染优化 | 高 | |
| 4 | 动画性能 | 高 | |
| 5 | 图片与资源加载 | 中高 | |
| 6 | 内存管理 | 中 | |
| 7 | 异步与数据获取 | 中 | |
| 8 | 平台专属优化 | 中低 | |
Quick Reference
快速参考
1. App Startup & Bundle Size (CRITICAL)
1. 应用启动与包体积(关键)
- - Enable Hermes JavaScript engine
startup-enable-hermes - - Remove console logs in production
startup-remove-console-logs - - Control splash screen visibility
startup-splash-screen-control - - Preload critical assets during splash
startup-preload-assets - - Use async routes for code splitting
startup-async-routes - - Use direct imports instead of barrel files
startup-cherry-pick-imports
- - 启用Hermes JavaScript引擎
startup-enable-hermes - - 生产环境移除控制台日志
startup-remove-console-logs - - 控制启动页可见性
startup-splash-screen-control - - 启动页期间预加载关键资源
startup-preload-assets - - 使用异步路由实现代码分割
startup-async-routes - - 使用直接导入而非桶文件
startup-cherry-pick-imports
2. List Virtualization (CRITICAL)
2. 列表虚拟化(关键)
- - Use FlashList instead of FlatList
list-use-flashlist - - Provide accurate estimatedItemSize
list-estimated-item-size - - Use getItemType for mixed lists
list-get-item-type - - Stabilize renderItem with useCallback
list-stable-render-item - - Provide getItemLayout for fixed heights
list-get-item-layout - - Memoize list item components
list-memoize-items
- - 使用FlashList替代FlatList
list-use-flashlist - - 提供准确的estimatedItemSize
list-estimated-item-size - - 混合列表使用getItemType
list-get-item-type - - 用useCallback稳定renderItem
list-stable-render-item - - 为固定高度列表提供getItemLayout
list-get-item-layout - - 对列表项组件进行记忆化处理
list-memoize-items
3. Re-render Optimization (HIGH)
3. 重渲染优化(高)
- - Memoize expensive computations
rerender-use-memo-expensive - - Stabilize callbacks with useCallback
rerender-use-callback-handlers - - Use functional setState updates
rerender-functional-setstate - - Use lazy state initialization
rerender-lazy-state-init - - Split context by update frequency
rerender-split-context - - Derive state instead of syncing
rerender-derive-state
- - 对高开销计算进行记忆化
rerender-use-memo-expensive - - 用useCallback稳定回调函数
rerender-use-callback-handlers - - 使用函数式setState更新
rerender-functional-setstate - - 使用惰性状态初始化
rerender-lazy-state-init - - 按更新频率拆分Context
rerender-split-context - - 推导状态而非同步状态
rerender-derive-state
4. Animation Performance (HIGH)
4. 动画性能(高)
- - Enable native driver for animations
anim-use-native-driver - - Use Reanimated for complex animations
anim-use-reanimated - - Use LayoutAnimation for simple transitions
anim-layout-animation - - Animate transform instead of dimensions
anim-transform-not-dimensions - - Defer heavy work during animations
anim-interaction-manager
- - 为动画启用原生驱动
anim-use-native-driver - - 复杂动画使用Reanimated
anim-use-reanimated - - 简单过渡使用LayoutAnimation
anim-layout-animation - - 动画transform而非尺寸属性
anim-transform-not-dimensions - - 动画期间延迟高开销任务
anim-interaction-manager
5. Image & Asset Loading (MEDIUM-HIGH)
5. 图片与资源加载(中高)
- - Use expo-image for image loading
asset-use-expo-image - - Prefetch images before display
asset-prefetch-images - - Request appropriately sized images
asset-optimize-image-size - - Use WebP format for images
asset-use-webp-format - - Use recyclingKey in FlashList images
asset-recycling-key
- - 使用expo-image加载图片
asset-use-expo-image - - 图片显示前预加载
asset-prefetch-images - - 请求合适尺寸的图片
asset-optimize-image-size - - 使用WebP图片格式
asset-use-webp-format - - FlashList图片使用recyclingKey
asset-recycling-key
6. Memory Management (MEDIUM)
6. 内存管理(中)
- - Clean up subscriptions in useEffect
mem-cleanup-subscriptions - - Clear timers on unmount
mem-clear-timers - - Abort fetch requests on unmount
mem-abort-fetch - - Avoid inline objects in props
mem-avoid-inline-objects - - Limit list data in memory
mem-limit-list-data
- - 在useEffect中清理订阅
mem-cleanup-subscriptions - - 组件卸载时清除定时器
mem-clear-timers - - 组件卸载时终止请求
mem-abort-fetch - - 避免在props中使用内联对象
mem-avoid-inline-objects - - 限制内存中的列表数据量
mem-limit-list-data
7. Async & Data Fetching (MEDIUM)
7. 异步与数据获取(中)
- - Fetch independent data in parallel
async-parallel-fetching - - Defer await until value needed
async-defer-await - - Batch related API calls
async-batch-api-calls - - Cache API responses locally
async-cache-responses - - Refetch data on screen focus
async-refetch-on-focus
- - 并行获取独立数据
async-parallel-fetching - - 延迟await直到需要值时
async-defer-await - - 批量处理相关API调用
async-batch-api-calls - - 本地缓存API响应
async-cache-responses - - 页面获焦时重新获取数据
async-refetch-on-focus
8. Platform Optimizations (LOW-MEDIUM)
8. 平台专属优化(中低)
- - Reduce Android overdraw
platform-android-overdraw - - Optimize iOS text rendering
platform-ios-text-rendering - - Enable ProGuard for Android release
platform-android-proguard - - Platform-specific optimizations
platform-conditional-render
- - 减少Android过度绘制
platform-android-overdraw - - 优化iOS文本渲染
platform-ios-text-rendering - - Android发布版启用ProGuard
platform-android-proguard - - 平台专属优化处理
platform-conditional-render
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
阅读单个参考文件获取详细说明和代码示例:
- 章节定义 - 类别结构与影响程度说明
- 规则模板 - 添加新规则的模板
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded, see AGENTS.md.
如需查看所有规则展开的完整指南,请参考AGENTS.md。
Reference Files
参考文件
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
| 文件 | 描述 |
|---|---|
| AGENTS.md | 包含所有规则的完整编译指南 |
| references/_sections.md | 类别定义与排序说明 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本与参考信息 |