AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

react-native-best-practices

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.

Original source
callstackincubator
License
MIT
Pinned revision
59e9d17446a248b21d86f078fcd0bd2d36db1ca4

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

This skill also requires local files or dependencies. Remote reading alone may not be enough.

Ask your assistant

Use Agentic Memory skills to read callstackincubator--react-native-best-practices at revision 59e9d17446a248b21d86f078fcd0bd2d36db1ca4, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 31

references/js-profile-react.md


title: Profile React Performance impact: MEDIUM tags: profiling, devtools, re-renders, flamegraph

Skill: Profile React Performance

Identify unnecessary re-renders and performance bottlenecks in React Native apps using React Native DevTools through agent-device react-devtools.

Quick Command

agent-device react-devtools status
agent-device react-devtools wait --connected
agent-device react-devtools profile start
agent-device react-devtools profile stop
agent-device react-devtools profile slow --limit 5
agent-device react-devtools profile rerenders --limit 5
agent-device react-devtools profile timeline --limit 20

Drive the target interaction with normal agent-device commands between profile start and profile stop. For targeted audits, profile the exact flow under review. Baseline output should include commit timeline, re-render counts, slow components, and a breakdown of the heaviest commit.

When to Use

  • App feels sluggish or janky during interactions
  • Need to identify which components re-render unnecessarily
  • Investigating slow list scrolling or form inputs
  • Before applying memoization or state management changes

Prerequisites

  • React Native DevTools connection available through agent-device react-devtools
  • App running in development mode
  • React DevTools version compatible with the app's React and React Native versions
  • For release-build profiling, @callstack/inspector installed and connected first

Note: Prefer agent-device react-devtools over the visual DevTools UI for token-efficient React profiling and debugging. Use the visual UI or exported profiler JSON only when the CLI output is insufficient. Record concrete commit times, render counts, and component names.

Manual fallback when agent-device is unavailable: open React Native DevTools from Metro (j) or the Dev Menu, use the Profiler tab, and record the same interaction. Keep this as fallback only; agent runs should prefer the CLI summaries above.

Step-by-Step Instructions

1. Connect React Native DevTools

agent-device react-devtools status
agent-device react-devtools wait --connected

If status reports the helper is not running, start it first:

agent-device react-devtools start
agent-device react-devtools wait --connected

Release Builds

React Native release builds do not expose the same profiling path by default. Before using agent-device react-devtools against a release app, wire in @callstack/inspector:

npm install @callstack/inspector
npx inspector start

Import @callstack/inspector as the first module in the app entrypoint, wrap Metro config with withInspector(config, true), then build and run the app in release mode. For Expo, use a release build from prebuild/dev-client flow; Expo Go is not a release-build profiling target.

2. Record a Profiling Session

agent-device react-devtools profile start
agent-device react-devtools profile stop

Drive the exact interaction or navigation flow under review between those two commands.

For AI-agent workflows, treat this as a required sequence:

  1. Run agent-device react-devtools status.
  2. Run agent-device react-devtools wait --connected.
  3. Start profiling immediately before the audited interaction.
  4. Drive the flow with normal agent-device commands.
  5. Stop profiling.
  6. Inspect slow components, re-render counts, and commit timing before proposing fixes.

3. Analyze Results

React DevTools Flamegraph

Use bounded CLI summaries first:

agent-device react-devtools profile slow --limit 5
agent-device react-devtools profile rerenders --limit 5
agent-device react-devtools profile timeline --limit 20

Then drill into a specific component:

agent-device react-devtools profile report @c5
agent-device react-devtools get component @c5

Use the component ref printed by profile slow, profile rerenders, or get tree; @c5 is only an example.

Use the visual flame graph or exported profiler JSON only when the bounded CLI summaries do not answer the question.

4. Profile JavaScript CPU

For non-React CPU issues, use platform CPU profilers or agent-device perf instead of React DevTools render profiling.

Interpreting Results

| Symptom | Likely Cause | Solution | |---------|--------------|----------| | Many yellow components | Cascading re-renders | Add memoization or use React Compiler | | "Props changed" on callbacks | Inline functions recreated | Use useCallback | | "Parent component rendered" | State too high in tree | Move state down or use atomic state | | Long JS thread block | Heavy computation | Move to background or use useDeferredValue |

Only propose callback or dependency-array changes when the profiler or a reproducible bug shows they matter. Do not infer stale closures from a snippet alone.

Common Pitfalls

  • Using one build type for every question: Use agent-device react-devtools in development to identify render causes, commit patterns, and expensive components. Validate timing-sensitive FPS/CPU improvements in production or release-like builds.
  • Not using production builds: Some issues only appear with minified code
  • Ignoring "Why did this render?": This tells you exactly what to fix
  • Using component tree depth or count as the main baseline: These are secondary context, not the core performance signal

Related Skills