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

vime

v0.0.1

Published

A faster VM module.

Downloads

10

Readme

vime, a faster vm module

Synopsis

Execute JS code in a new VM context.

Motivation

The built-in vm module is flexible but slow. Code sometimes runs 200x slower inside a vm context than outside. Vime sacrifices some flexibility in exchange for fast and reliable performance.

Usage

The module exports a single function.

const vime = require('vime');
const result = vime('1 + 1');
console.log(result);  // Prints "2".

To execute more code in the same vime context, first grab a reference to the global object (or any other object from the context):

const vime = require('vime');
const context = vime('this');
vime('var x = 1', context);
console.log(vime('x + x', context));  // Prints "2".

Exporting functions from the main context is done in similar fashion:

const vime = require('vime');
const context = Object.assign(vime('this'), { console, require });
vime('console.log(require("./package.json"))');

It follows that vime() is not restricted to running JS code in a new context, you can also execute it in the current context:

const vime = require('vime');
const context = global;  // Or any object from this context.
vime('console.log("ok")', context);  // Prints "ok".

Caveats

instanceof checks don't work across contexts because each context gets its own copy of Object, Array, and other built-ins.

const vime = require('vime');
const array = vime('[]');
console.log(Array.isArray(array));  // Prints "true".
console.log(array instanceof Array);  // Prints "false".

References to objects from a context keep the context alive until the last reference goes away. Because contexts are heavy-weight objects (a context is a complete JS runtime), keeping many contexts around has a notable impact on memory usage:

const vime = require('vime');
console.log(process.memoryUsage().rss >>> 20);  // 25 MB on my machine.
const leak = [];
for (let i = 0; i < 100; ++i) leak.push(vime('this'));
console.log(process.memoryUsage().rss >>> 20);  // 100 MB on my machine.

Use node-heapdump or the built-in inspector to debug such issues.

Important note: this module is currently not designed for executing untrusted code ("sandboxing.") If that is an important use case for you, please file a bug report.

Reporting bugs

Report bugs at https://github.com/bnoordhuis/vime/issues. Please check existing issues first. If possible, include a test case demonstrating the bug.

UNIX users, please include the output of node -v and uname -a.

Windows users, please include the output of node -v and winver.

When reporting build errors, include the full terminal output from npm install vime on down and the output of g++ -v or clang++ -v (if you are a UNIX user) or the version of Visual Studio or Build Tools (if you are a Windows user.)

License

ISC. See the LICENSE file in the top-level directory.