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

memory-efficient-object

v0.4.1

Published

Memory efficient implementation of objects / arrays for bits and bytes mainpulation (int, char, uint, ...) in JS, using schema for serialisation

Downloads

2

Readme

CircleCI

Introduction

NPM

this package is a very light (no dependencies) module to drastically optimise the usage of memory in data-driven application. Using basic objects/arrays in JS is very sub-optimal, and typed array often fail to fit people's needs. Also, using JSON to serialise your data leads to major bottleneck in disk / memory / network usage. This library cater for this problem by providing an implementation of an array with bit-per-bit optimisation of your memory usage.

alt text

Exemple spawning 65536 arrays of 128 int of variable size in JS.

tests are available :

npm run test

Usage

npm install memory-efficient-object

Example of usage :

const {schemaEngine, MEObject} = require('memory-efficient-object');

const schema = {
    "id" : "uint(2)",
    "letter" : "char",
    "isBlue" : "bool",
    "size" : "uint(32)",
    "x" : "int(32)",
    "name" : "string(4)",
    "coords" : "uint(8)[3]",
    "lights" : "bool[3]"
};

let testSchema = schemaEngine.add(schema);

// 2nd argument optional values

let test = new MEObject(testSchema, { 
    id: 3,
    letter: 'A',
    isBlue: true,
    size: 4294967295,
    x: -5000,
    name: 'Yann',
    coords: [ 1, 2, 3 ],
    lights: [ true, false, true ]
});

// ...set some values
// ....

console.log(test.toJson());

/*
Will display :
{ id: 3,
  letter: 'A',
  isBlue: true,
  size: 4294967295,
  x: -5000,
  name: 'Yann',
  coords: [ 1, 2, 3 ],
  lights: [ true, false, true ] }
*/

console.log(test.serialize());

/*
    Will display: ǿ￿￿↓硙慮渁ȃԀ
    As you can appreciate, this is a much smaller string (10 char vs. 150).
*/

// serialize then unserialize
let testUnSerialised = new MEObject(testSchema, test.serialize());
console.log(testUnSerialised.toJson());

// will re-display the same JSON object again after unserialization 

More details :


const {schemaEngine, MEObject} = require('memory-efficient-object');

// Define your schema

const schema = {
    "id" : "uint(2)"
};

// This add it to the schema engine which compiles it and keeps it

let testSchema = schemaEngine.add(schema);

// Create an Object using this schema

let test = new MEObject(testSchema);

// set a value

test.set("id", 1)

// get a value

test.get("id")

Schema Definition

Available datatypes

| Name | description | length | | ------------- |:-------------: | -----:| | bit | simply a bit | 1 | | bool | Same than bit, but will accept / return true/false instead of 0/1 automatically | 1 | | char | Same than uint(8), but will accept / return a character automatically | 8 | | uint(n) | Unsigned Int of size n | n | | int(n) | signed Int of size n | n | | string(n) | string of size n | n * 8 |

use arrays

const {schemaEngine, MEObject} = require('../index');

const schema = {
    "coords" : "uint(8)[3]",
};

let testSchema = schemaEngine.add(schema);
let test = new MEObject(testSchema);

test.set("coords", [1,2,3]);
test.get("coords"); // [1,2,3]
test.get("coords", 1); // 2

Note on usage

Choose your datatypes very carefully, using as few bytes as you can, this is the key to optimising your app !

The serialised output of this library is compression friendly, bare in mind that until defragmentation is implemented, only dataset with bigger datatypes will benefit from it.

ToDo

  • fill gaps between values dynamically