npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-snoopy

v2.0.2

Published

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

Downloads

1,153

Readme

React Native 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.

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 [email protected]

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.