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

@deepkit/bson

v1.0.1-alpha.155

Published

Deepkit BSON parser

Downloads

3,325

Readme

BSON

@deepkit/bson is a high-performance TS implementation of a parser and serializer for BSON, the MongoDB Binary JSON format. It's the fastest JS BSON parser, even faster than native JSON.parse/stringify.

Deepkit has reimplemented it because it's a high-performance framework and both the official JS (js-bson) and C++ (bson-ext) packages are too slow. How slow? When converting 10k elements in an array, js-bson takes 25ms, bson-ext takes 31ms, whiles JSON.parse takes only 5ms. This makes the official BSON parser 5x slower than native JSON.parse. deepkit/type-bson on the other hand takes only 2ms and is therefore 13x faster.

Benchmark

Parsing BSON buffer that contains an array with 10k objects.

| Method | Time (ms) | | ------ | --------: | | official native bson-ext | 31ms | | official js-bson | 25ms | | deepkit/bson generic v2 | 6ms | | deepkit/bson generic v3 | 4ms | | JSON.parse | 5ms | | deepkit/type JIT | 2ms |

Serializing an array with 10k objects.

| Method | Time (ms) | | ------ | --------: | | official native bson-ext | 39ms | | official js-bson | 33ms | | JSON.stringify | 5ms | | deepkit/bson JIT | 2ms |

"deepkit/bson JIT" means a parser/serializer based on a schema like so:

import {t} from '@deepkit/type';
import {getBSONDecoder} from '@deepkit/bson';

interface Model {
    username: string;
    tags: string[];
    priority: number;
}

const decoder = getBSONDecoder<Model>();
const bson = new Buffer([]);

const document = decoder(bson);

whereas "deepkit/type generic" means schema-less:

import {parseObject, ParserV2, ParserV3} from '@deepkit/bson';
const bson = new Buffer([]);

const object1 = parseObject(new ParserV2(bson));

const object2 = parseObject(new ParserV3(bson));

Differences

There are a couple of differences to the official serializer.

  • ObjectId is deserialized as string.
  • UUID is deserialized as string.
  • BigInt is supported and serialized as long.
  • Unlimited size BigInt supported (serialised as binary)
  • Long is deserialized as BigInt.