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

live-perf

v0.0.3

Published

A collection of ways to improve startup time, and measure time taken to require npm modules.

Downloads

4

Readme

live-perf

A collection of ways to improve startup time, and measure time taken to require npm modules.

const Perf = require('live-perf')
const perf = new Perf({
  useDeduper: false,
  useRequireTimes: false,
  logRequires: false,
  useRequireClock: false,
  useTimeRequires: false,
})
perf.start()

// Your app's startup methods, etc.

perf.end({log: false})

API

perf.start()

Call this to install hooks and start tracking requires.

perf.end({log})

Call this to finish tracking and show summary information.

Options

useDeduper

WARNING: Currently the deduper adds more time than it saves. The issue is dynamically finding the correct version is expensive. I have isolated the hot function and caching should improve this.

Enable to dedupe modules at runtime.

This simply overrides Module._resolveFilename, which is used to convert a require request (e.g. require('lodash') to an absolute path (e.g. /path/to/project/node_modules/lodash/index.js).

Every time require is used:

First, we get the version specified in the closest package.json file.

  1. If there is a top-level dep that satisfies, use that.
  2. If a satisfying module is present in ~/.live-perf-store/node_modules/.store (a pnpm project), use that.
  3. After this, we resolve symlinks, such that if more than one module is symlinked to the same module, they will both resolve to the same one.

useRequireTimes

Lists all modules that are required in your app, and all the different versions specified in package.json files.

logRequires

Print a log message everytime a module is required. For rough debugging.

useRequireClock

Lists all modules that are required in your app, and the files which require them, and whether they are being dynamically deduped.

useTimeRequires

When you ctrl+c from your app it will use the time-requires npm module to show you a list of the modules taking the most time to be required.

Test

No tests at the moment.

Examples

Run: cd examples && node main

In examples/main/index.js, toggle the following value to see what happens with and without deduping: const useDeduper = true

To capture a CPU profile to view in Chrome DevTools run cd examples && node --inspect main and open the link printed in the console. Your profile will be viewable in the Profiles tab.

Development

npm run gulp watch

Using Chrome Debugger

There is a native inspector in Node >6.3.

This allows you to profile your app in the Chrome DevTools.

cd examples && node --inspect main

Use --debug-brk if you want to halt when the app starts.

To automatically capture a CPU profile on startup:

console.profile('my-profile')
require('./my-app')
console.profileEnd('my-profile')

Your profile will be viewable in the Profiles tab.

This will mainly be useful to see how expensive the deduping code is.

See examples/main/index.js for a full working example.