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

sanic.js

v1.1.3

Published

JS Native Functions gotta go fast

Downloads

902

Readme

sanic.js

Build Status codecov

Support of this lib with evolution of Javascript (1.1.3 / Node 16 / 22-07-26)

V8 engine evolved a lot since this project began. Few functions are still better with sanic.js, but a lot of them are now fully optimized in last versions of V8 engine (and Node.js/Chromium browsers). Except if I found a new trick exploding again performance of these functions (which is really hard with the good evolution of V8), this library is currently a story of the past. I have some tries to do with WebAssembly and N-Api. It was bad last time due to load overhead of C programs, but time has passed and these methods can be good today. So avoid to use this library while there's not any new big updates (1.1.3 at the time I wrote this message), and keep doing some readable code. Readable code is optimized code.

TL;DR: You shouldn't use this library anymore, except if you have some important performance problems with the last available functions.


Benchmarks between JS classic methods and Sanic methods here.


Another new day in the Javascript's world, and this fucking Array.prototype.map() function is always slow. But Sanic is here to save Javascript from the performance hell. GOTTA GO FAST !

sanic.js is a library which increases Javascript natives functions performance to the detriment of some unused cases of EcmaScript specification. For example, this library removes hasOwnProperty() check in Array methods, because nobody uses Array methods for an Object. (Why am I saying that : See Note 2 of this paragraph).

This project has 2 common uses :

  • like any other library with a classic object with methods.
  • with a special require changing prototype of natives objects concerned (Array, Object, ...) (monkey patching).

gosh you're changing prototype of native objects taht's baaaaaaaad !!!!! :((

The advantage of this bad technic is performances of all library called after sanic.js will be impacted, and using this technic is only one line away :

    require('sanic.js').changeMyWorld();

Due to the danger of the library, there's a lot of unit test and performance tests to try to protect you from bugs. But anyway, there are always bugs, so please report them in Issues section.

Installation

    npm install --save sanic.js

API

Fast use

This mode replaces all prototypes methods by their Sanic equivalents. Sanic methods are written with same parameters than natives prototypes methods. The goal is to give faster functions without any code adaptation.

    require('sanic.js').changeMyWorld();

    const myArray = [1, 2, 3, 5, 8];

    console.log(
        // Yeah, Sanic is activated but there's no code to change
        myArray.reduce((acc, n) => acc + n)
    );

Library use

In this mode, all functions need the object to use to the first parameter and all classic parameters after.

    const Sanic = require('sanic.js').Library;
    const myArray = [1, 2, 3, 5, 8];

    console.log(
        Sanic.Array.reduce(myArray, (acc, n) => acc + n)
    );

Available reworked functions

Array

  • Array.prototype.every() (removed in 1.1.3)
  • Array.prototype.fill()
  • Array.prototype.find() (removed in 1.1.3)
  • Array.prototype.filter() (removed in 1.1.3)
  • Array.prototype.forEach() (removed in 1.1.3)
  • Array.prototype.map()
  • Array.prototype.reduceRight() (removed in 1.1.3)
  • Array.prototype.reverse() (removed in 1.1.3)
  • Array.prototype.some()

Object

  • Object.assign()
  • Object.clone() (optional method)

Performance

    # Run all benchmarks
    npm run benchmark

    # Run specific benchmarks
    npm run benchmark Array.reduce Array.map

    # Method can be set to 'all' to test all methods of a class
    npm run benchmark Array.all

Benchmarks here

Experimental functions

To create this library, I do some bench tests on each function detailed in EcmaScript. But sometimes, natives functions are faster. So I keep my bad functions and I call them experimental functions. That's why there are more functions available in benchmarks than in lib.

If you want to test the performance of these functions (in the case of you want to help this library or others things) :

    # Run all benchmarks
    npm run exp

    # Run specific benchmarks
    npm run exp Array.map Array.indexOf

    # Method can be set to 'all' to test all methods of a class
    npm run exp Array.all

This is the same command line than benchmarks, but it enables a new flag which allows using experimental functions.

Array

  • Array.prototype.concat()
  • Array.prototype.includes()
  • Array.prototype.indexOf()
  • Array.prototype.join()
  • Array.prototype.lastIndexOf()
  • Array.prototype.push()
  • Array.prototype.reduce()
  • Array.prototype.shift()
  • Array.prototype.unshift()

License

MIT (LICENSE)

Thanks to

  • KBDev