An open API service indexing awesome lists of open source software.

https://github.com/be9/faster-pbts

A faster alternative for pbts from protobuf.js
https://github.com/be9/faster-pbts

Last synced: 7 months ago
JSON representation

A faster alternative for pbts from protobuf.js

Awesome Lists containing this project

README

          

# faster-pbts

[pbts]: https://github.com/protobufjs/protobuf.js/

[![npm version](https://img.shields.io/npm/v/faster-pbts.svg)](https://www.npmjs.com/package/faster-pbts)
[![license](https://img.shields.io/npm/l/faster-pbts.svg)](./LICENSE)

A faster alternative to [pbts], the TypeScript typings generator from `protobuf.js`.

## 🚀 Motivation

For large Protobuf collections, `pbts` can be slow and memory-intensive. This is due to its reliance on [JSDoc](https://www.npmjs.com/package/jsdoc), which is not optimized for performance.

For example, with a collection of ca. 2000 `.proto` files, `pbjs` produces a 233MB JavaScript file. Generating TypeScript typings from it using `pbts` takes approximately **13 minutes** and requires increasing memory limits:

```bash
NODE_OPTIONS=--max_old_space_size=16384 pbts ...
```

## âš¡ How `faster-pbts` Works

Like `pbts`, `faster-pbts` extracts types from JSDoc annotations generated by `pbjs`.
The key difference is the implementation:

* Uses [tree-sitter-javascript] and [tree-sitter-jsdoc] for fast, incremental parsing.
* Processes input in **streaming mode**, significantly reducing memory usage.

As a result, generating typings for the same 233MB file takes **under 1 minute**.

## 📦 Installation & Usage

```bash
# Add the package to your project
npm install faster-pbts

# Generate typings
node_modules/.bin/faster-pbts -o output.d.ts input.js
```

* `input.js` should be the output file generated by `pbjs`.
* This tool is a drop-in replacement for `pbts` in most workflows.

Use `--help` to see other available options.