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

fast-json-bigint

v1.0.5

Published

nodejs JSON.parse 解析 number 范围为 `[-9007199254740991, 9007199254740991]`,无法处理 int64, 被广泛使用的方案是 [json-bigint](https://www.npmjs.com/package/json-bigint), 但这个库的性能实在太慢了,处理大 JSON 会严重阻塞 node 主线程。

Downloads

3

Readme

介绍

nodejs JSON.parse 解析 number 范围为 [-9007199254740991, 9007199254740991],无法处理 int64, 被广泛使用的方案是 json-bigint, 但这个库的性能实在太慢了,处理大 JSON 会严重阻塞 node 主线程。

yyjson 是一个高性能的 JSON 解析库,性能测试见[https://github.com/ibireme/yyjson]

我基于这个库,修改了部分代码,利用 Node-API 提供给 nodejs 使用,相较于 json-bigint 可以大幅提升性能。

特别声明:该项目利用 yyjson https://github.com/ibireme/yyjson/blob/master/LICENSE 做JSON 解析

benchmark

对某个 json string 解析10次耗时统计:

small data test ----------------
        JSON.parse:  7ms
  fast-bigint-json:  11ms
       json-bigint:  57ms

mid data test ----------------
        JSON.parse:  47ms
  fast-bigint-json:  90ms
       json-bigint:  277ms

big data test ----------------
        JSON.parse:  200ms
  fast-bigint-json:  521ms
       json-bigint:  1580ms

可以看出,不管是解析简单或复杂的数据,效率提升都是巨大的

注意事项

  1. 当 number 是以指数的形式表示时,只要他的处理范围超过 [-9007199254740991, 9007199254740991] 那么也会被转为字符串

{ v1: 1e-24, v2: 123000000000000000, v3: 1.234e+21 }

=>

{ v1: 1e-24, v2: '123000000000000000', v3: '1.234e21' }