Snoopy is a profiling tool for React Native, that lets you snoop on the React Native Bridge.
Go to file
Roman Volosovskyi f23dc13469
add thresholdMessage
2018-01-26 11:26:44 +02:00
examples/Snoopful apply a few tweaks 2017-12-06 19:51:18 +02:00
media add filtering gif 2016-07-27 08:57:38 +03:00
stream add thresholdMessage 2018-01-26 11:26:44 +02:00
.eslintrc.js apply a few tweaks 2017-12-06 19:51:18 +02:00
.gitignore setup eslint 2017-12-05 15:43:07 +00:00
.npmignore apply a few tweaks 2017-12-06 19:51:18 +02:00
CHANGELOG.md bump version, add changelog 2016-12-03 16:07:11 +02:00
README.md update readme 2017-12-05 12:04:30 +00:00
formatting.js Update formatting.js 2016-08-03 22:37:40 +03:00
index.js Fixed MessageQueue import 2016-12-03 11:56:58 +03:00
log.js ii 2016-07-24 11:03:33 +03:00
package.json bump 2017-12-07 14:48:06 +02:00
yarn.lock apply a few tweaks 2017-12-06 19:51:18 +02:00

README.md

React Native Snoopy

Snoopy



UPDATE: I wrote an article with the story behind this library.

Snoopy is a profiling tool for React Native, that lets you snoop on the React Native Bridge using the MessageQueue spy feature.

With Snoopy you can tame a stream of events, using Rx and a few built-in goodies, to locate performance hogs, problems, and expose unexpected communications on the bridge.

The React Native bridge is the hub where communication between the Javascript and the Native world happen. Optimizing and catching unexpected (bad) communications can make or break your performance. Being that central and sensitive place, it made sense to have tooling built around it.

NOTE: Snoopy is a developer tool, and you might want to flag it under __DEV__. I felt not doing this by default inside Snoopy will allow for creative uses even in production.

Aggregating and Charting Events with Bar Filtering Create Views Only

Quick Start

$ npm install -S rn-snoopy

First, find a place to initialize Snoopy and the event stream, doesn't matter where, but preferably under an if(__DEV__) guard.

// core Snoopy
import Snoopy from 'rn-snoopy'

// some Snoopy goodies we're going to use
import bars from 'rn-snoopy/stream/bars'
import filter from 'rn-snoopy/stream/filter'
import buffer from 'rn-snoopy/stream/buffer'

import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';

const emitter = new EventEmitter()

const events = Snoopy.stream(emitter)

In the following examples, we're going to use info, the call descriptor.

{
  type: int (0=N->JS, 1=JS->N)
  method: string,
  module: string,
  args: object,
}

Examples

Show only calls going from Javascript to Native create an info shape with Snoopy.TO_NATIVE. Use true to log filter results.

filter({ type: Snoopy.TO_NATIVE }, true)(events).subscribe()

Show calls to createView. Filter based on method, and provide a shape to match it.

filter({ method:'createView' }, true)(events).subscribe()

Drill down and show only calls with specific arguments, using nested matching.

filter({ method:'createView', {args: {foo: {bar:1}}}}, true)(events).subscribe()

Or use a function.

filter((info)=>info.method == 'createView', true)(events).subscribe()

Visualize "excessive" calls across the bridge. Group and aggregate calls per second.

bars()(
  buffer()(
    events
  )
).subscribe()

Visualize "heavy" calls across the bridge. Use a heuristic: serialize arguments and take the size.

bars(info=>JSON.stringify(info.args).length)(
  events
).subscribe()

Visualize "heavy" calls across the bridge. Set a threshold (100) and pop a Yellowbox (true) in Simulator to warn about crossing the threshold.

bars(info=>JSON.stringify(info.args).length
  200 /*command string length threshold*/,
  true /*show yellow box*/
)(events).subscribe()

Visualize "heavy" calls, only for view creation. This filters on createView and takes a look at the argument data size.

bars(info=>JSON.stringify(info.args).length)(
    filter({ method:'createView' })(events)
).subscribe()

React Native Below 0.33

I've submitted a modification to MessageQueue that allows for more flexible bridge spy, which was made available starting React Native v0.33. Versions 0.33 and up will work seamlessly with Snoopy.

For versions below 0.33, you have the option of locking to a legacy version of Snoopy which installs the required MessageQueue modifications by patching it externally:

$ npm i rn-snoopy@1.0.6

Contributing

Fork, implement, add tests, pull request, get my everlasting thanks and a respectable place here :).

Thanks:

To all Contributors - you make this happen, thanks!

Copyright

Copyright (c) 2016 Dotan Nahum @jondot. See LICENSE for further details.