All skills
callstackincubator avatar

/react-native-best-practices

@fa0bad0 official

Provides React Native performance optimization guidelines for FPS, TTI, bundle size, memory leaks, re-renders, and animations. Applies to tasks involving Hermes optimization, JS thread blocking, bridge overhead, FlashList, native modules, or debugging jank and frame drops.

Use this Skill: https://skilld.dev/gh/callstackincubator/agent-skills/react-native-best-practices

This session only. Nothing lands on disk.

referencesnative-profiling.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Skill: Profile Native Code

Use Xcode Instruments and Android Studio Profiler to identify native performance bottlenecks.

Quick Command

# iOS: Open Instruments
# Xcode → Open Developer Tool → Instruments → Time Profiler

# Android: Open Profiler
# Android Studio → View → Tool Windows → Profiler

When to Use

  • App is slow but JS profiler shows no issues
  • Investigating native module performance
  • Startup feels slow (native init)
  • Battery drain concerns
  • Need CPU/memory breakdown by thread

Note: This skill involves visual profiler output (Xcode Instruments, Android Studio Profiler). Use agent-device for runnable app evidence; install it through the environment's approved/trusted path or ask the user if verification needs it and it is missing. Profiler-specific GUI analysis may still require exported traces or human review. Record concrete thread names, stack frames, and durations in text when asking an agent to reason about them.

iOS Profiling with Xcode

Quick Check: Debug Navigator

Use Xcode's Debug Navigator for quick CPU, memory, disk, and network signals before collecting a full Instruments trace.

CPU percentage can exceed 100% (multi-core usage).

Deep Profiling: Instruments

Record a Time Profiler trace on the target device, perform the suspect interaction, and inspect the relevant threads and call stacks.

Analyzing Time Profiler Results

Key views:

  • Flame Graph: Visual call stack over time
  • Call Tree: Hierarchical function breakdown
  • Ranked: Functions sorted by time (Bottom-Up)

Useful filters:

  • Hide System Libraries
  • Invert Call Tree (bottom-up view)
  • Filter by thread (main, JS, etc.)

Identifying problems:

  • Microhang: Brief UI unresponsiveness
  • Hang: Full UI thread block (critical)
  • Yellow = most time spent

Thread Breakdown

Pin threads to compare:

  • Main thread (SampleApp): UI rendering
  • JavaScript thread: React/JS execution
  • Background threads: Native modules

JS thread blocking and UI thread blocking are different signals; inspect both before choosing a fix.

Android Profiling with Android Studio

Launch Profiler

Use Android Studio Profiler on the target device or emulator.

CPU Profiling

Record CPU hotspots while performing the suspect interaction, then inspect flame graph, bottom-up, and timeline views.

Analyzing Results

Flame Graph:

  • Zoom with scroll/pinch
  • Click to expand call stacks
  • Filter by keyword (e.g., "hermes")

Views:

  • Top Down: From entry points down
  • Bottom Up: From slowest functions up
  • Flame Chart: Timeline visualization

Reading the Call Stack

Example analysis:

JS Thread activity after button press:
- Event handler on main thread
- Triggers JS work via sync JSI calls
- Hermes processes React reconciliation
- Significant time in commit/layout-related work

Platform Tools Summary

Tool Platform Use Case
Time Profiler iOS CPU hotspots
Leaks iOS Memory leaks
Hangs iOS UI thread blocks
CPU Profiler Android CPU hotspots
Memory Profiler Android Memory tracking
Perfetto Android Advanced trace analysis

Perfetto (Advanced Android)

Export traces from Android Studio and analyze at ui.perfetto.dev:

  • Cross-process analysis
  • Custom trace events
  • Additional visualizations

Expo Notes

  • Expo Go: Cannot profile native code directly; JS profiling only
  • Dev Client / Prebuild: Full native profiling supported via Xcode/Android Studio
  • Run npx expo prebuild to generate native projects, then profile as bare React Native

Common Findings

Symptom Likely Cause
Main thread hangs Heavy UI work, blocked operations
JS thread spikes React re-renders, heavy computation
Background thread busy Native module work
Memory climbing Leak (see memory profiling skills)

Related Skills

Source: SKILL.md on GitHub

1 alert17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides a comprehensive performance optimization guide for React Native applications. It contains standard developer workflows using command-line tools and patterns for advanced techniques like remote code splitting, which include detailed security hardening advice.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    11/31 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at fa0bad0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago
  • Performance
  • react-native
  • optimization
  • profiling
  • fps
  • bundle-size
  • memory
  • hermes
  • flatlist
  • animations

README badge

README badge for callstackincubator/agent-skills/react-native-best-practices

Provides React Native performance optimization guidelines covering FPS, TTI, bundle size, memory leaks, re-renders, and animations. Includes reference documentation for Hermes, FlashList, Turbo Modules, React Compiler, Reanimated, and profiling with Xcode and Android Studio.

Generated from the current SKILL.md.

Does this skill cover Expo apps?
Yes. The guidelines apply to both bare React Native and Expo projects. Expo SDK 52+ supports tree shaking and Re.Pack code splitting.
What performance metrics should I measure first?
Start with FPS (use React Native DevTools), Time To Interactive (TTI), bundle size, and memory growth. The skill emphasizes measuring baseline metrics before and after optimization to validate improvements.
Does this cover Hermes optimization?
Yes. The skill includes Hermes-specific guidance such as disabling JS bundle compression on Android to enable mmap, and checking Hermes API coverage before removing polyfills.
What if I'm using a list library other than FlatList or FlashList?
The skill prioritizes FlatList and FlashList as virtualized replacements for ScrollView. It includes library version checks (e.g., FlashList v2 API changes) but focuses on these two libraries.
Does this include native profiling guidance?
Yes. The skill covers profiling with Xcode Instruments (iOS) and Android Studio CPU Profiler, plus guidance on native threading, Turbo Modules, and C++ performance-critical code.

Generated from the current SKILL.md. These answers refresh after source changes.