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

big-map

v0.1.1

Published

A big map, use buffer, help you exceed V8 heap memory limit

Downloads

4

Readme

Big Map for node js


This package provides you with a big map.
It uses Buffer as its storage space rather than heap memory.
It implemented by node js pure javascript code (ES6), no other dependencies.
Its feature is still relatively simple, and performance worse than build-in Object or Map,
but sometimes in order to get more space, we have no other choice.

Use Buffer implementation does not exist v8 engine heap memory limit of 1.4GB,
you can store 4GB, 8GB or more data therein, as long as sufficient physical memory.

When use

  • heap memory will not meet your demand
  • the keys and values have consistent data type
  • you know the max length of your key and value

When NOT use

  • performance sensitive
  • can not determine the data type
  • can not determine the max length of key or value
  • you need remove/delete entries

node compatibility

it needs node version >= 4.0 to support some es6 features. (arrow function, let ... )


Usage

install :
npm install big-map
quick start :
var BigMap = require('big-map');

var bigmap = new BigMap(16, 16);

bigmap.set('hello', 'world'); 
// -> true

bigmap.get('hello')
// -> 'world'
Heap Memory Usage
var BigMap = require('big-map');
var bigmap = new BigMap(32, 32);
var v8 = require('v8');

console.log('before: ', v8.getHeapStatistics().used_heap_size);

for (var i = 0; i < 1024 * 128; i ++ ) {
    bigmap.set('it\'s a long string key ' + i, 'it\'s a long string value' + i);
}

console.log('after: ', v8.getHeapStatistics().used_heap_size);

On my Mac, before is 10018984 and after is 10731160. the heap memory almost not change.

var obj = {};
var v8 = require('v8');

console.log('before: ', v8.getHeapStatistics().used_heap_size);

for (var i = 0; i < 1024 * 128; i ++ ) {
    obj['it\'s a long string key ' + i] = 'it\'s a long string value' + i;
}

console.log('after: ', v8.getHeapStatistics().used_heap_size);

As contrast, after the codes above, heap memory increase from 9400024 to 33636280, it grows 23MB. it has 128K key/value pairs, 23MB / 128K = 184 Byte per key/value pair costs.


new BigMap(key_length, value_length[, options])

construct a new BigMap

  • key_length : required. specify the max key string length. recommend a multiple of 4.
  • value_length : required. specify the max value string length. recommend a multiple of 4.
  • options : optional.
    • keyType : only support string now.
    • valueType : support string and number. default is string. note: if value type set to number, the value_length will be override by 8 (DoubleFloat).
    • loadFactor : default is 0.75
    • migrate : whether rehash data from old buffer to new bigger buffer. default is false
    • async_migrate : if migrate, use async mode or sync mode. default is false

set(key, value)

set key value pair to big map.

you should make sure the key and value has valid data type and length,
or else it will throw a error.

  • key : your string key
  • value : your value, default it needs string type. you can pass a number if you set valueType options to number.

return boolean, true if it success.

get(key)

get a value by the key.

  • key : your string key

return string or number, depends on the options. if not find the key, return undefined.

properties

  • .id : {string} BigMap id
  • .size : {number} the number of the elements have been set.
  • .migrating : {number} 0 if not in migrating status, or else, it has N MapBlocks in migrating status.

TODO

  • add more test case, make sure basic functionality
  • key support number type
  • add remove function
  • change data structure, add a meta byte