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

performance-spy

v0.0.28

Published

Performance spy - spy on common libraries and check their performance

Downloads

25,425

Readme

Performance Spy

How it works

It'll override the implentation of your favorite libraries!

  • React ( still WIP )
  • Redux Reducers
  • Redux Dispatches
  • Redux Thunk
  • Moment ( not implented yet )
  • reselect
  • re-reselect

And will tell you how much performance they take, and you can improve their usage.

For example if you have in reselect a function that takes 1 seconds each time, and gets calculated 5 times instead of once, it'll show you which arguments caused the cache to expire.

Why use it instead of profiler?

  1. Profilers work in samples, they check the stacktrace a few times in a ms, but in between there are lots of things you might miss and won't be able to find with it due to it.

  2. Profilers will usually be less guidy, they won't show you, this cache selector doesn't work well and broken.

Install

Install library

npm i performance-spy

Setup with webpack

1 - add to webpack.config.js:

alias: {
    /* my aliases */
    ...require("performance-spy").spyWebpackAliases(path.resolve("./node_modules"), [
      "redux-thunk",
      "re-reselect",
      "reselect",
      "redux"
    ])
}

it'll override redux/reselect with performance-spy libraries

2 - add to your init.js file, before any usage of one of the libraries

require("performance-spy").enableSpying();

Note that step 2 shouldn't be used in production, it'll have performance impact since all the libraries functions will be used through the library.. You can allow it though to a specific user in production for research with some condition.

Setup with jest

See example Example

1 - add to jest.config.js

moduleNameMapper: {
    // my name mappers...
    ...spyJesAliases("<rootDir>/node_modules", ["redux-thunk", "re-reselect", "reselect", "redux"])
}

2 - add to jest setup

require("performance-spy").enableSpying();

3 - to jest beforeEach

beforeEach(() => {
  perfStatsReset();
});

How to research with it

1 - load a page, do some actions

2 - run in f12 console:

getPerfSummary()

3 - you'll get a summary of what had happend

Measure a specific action

1 - load a page and prepare to do your action

2 - run in f12 console

perfStatsReset()

3 - do your action

4 - run in f12 console

getPerfSummary

5 - you'll see a summary of this action

Custom measures

If you have a function that you know it's slow, but you don't know which part you can use

const timer = startCustomTimer("measuring a")
// some actions
timer.end()

and then you'll see it as part of getPerfSummary

so you can divide and conquer your slow function until you find which part is slow:

const measureHeavy = startCustomTimer("heavy")
someHeavyStuff()
measureHeavy.end()

const measureLight = startCustomTimer("light")
someLightStuff()
measureLight.end()

const measureSuspect = startCustomTimer("suspicious")
SomeSuspiciousStuff()
measureSuspect.end()

and you'll get the answer which one is the slowing part? the heavy function? the suspicious? the light?

you can also provide data to it, for dynamic measure, to know which id had a slow transaction

const measureIdStuff = startCustomTimer("suspicious"+id)
heavyFunction(id)
measureIdStuff.end()