Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve 13608 - Expose RCTRenderingPerf output functions #13610

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Libraries/Performance/RCTRenderingPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ var RCTRenderingPerf = {
}

ReactPerf.stop();
ReactPerf.printInclusive();
ReactPerf.printWasted();
ReactDebugTool.removeHook(RCTRenderingPerfDevtool);

console.log(`Total time spent in render(): ${totalRenderDuration.toFixed(2)} ms`);
Expand All @@ -75,6 +73,30 @@ var RCTRenderingPerf = {
perfModules.forEach((module) => module.stop());
},

printInclusive: function() {
if (!enabled) {
return;
}

ReactPerf.printInclusive();
},

printWasted: function() {
if (!enabled) {
return;
}

ReactPerf.printWasted();
},

printExclusive: function() {
if (!enabled) {
return;
}

ReactPerf.printExclusive();
},

register: function(module: perfModule) {
invariant(
typeof module.start === 'function',
Expand Down
24 changes: 23 additions & 1 deletion docs/Performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,29 @@ Access it by selecting Perf Monitor from the Debug menu.

For iOS, Instruments is an invaluable tool, and on Android you should learn to use [`systrace`](docs/performance.html#profiling-android-ui-performance-with-systrace).

You can also use [`react-addons-perf`](https://facebook.github.io/react/docs/perf.html) to get insights into where React is spending time when rendering your components.
You can also use `RCTRenderingPerf` to get insights into where React is spending time when rendering your components.

```
import PerfMonitor from 'react-native/Libraries/Performance/RCTRenderingPerf'

// enable performance monitoring
PerfMonitor.toggle()

// start recording render performance
PerfMonitor.start()

// ...potentially slow code

// stop recording
PerfMonitor.stop()

// output stats to console
PerfMonitor.printExclusive()
PerfMonitor.printInclusive()
PerfMonitor.printWasted()
```

For more information on the output of the print functions, see the documentation for [`react-addons-perf`](https://facebook.github.io/react/docs/perf.html).

Another way to profile JavaScript is to use the Chrome profiler while debugging.
This won't give you accurate results as the code is running in Chrome but will give you a general idea of where bottlenecks might be.
Expand Down