Skip to content

be9/faster-pbts

Repository files navigation

faster-pbts

npm version 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, 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:

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

# 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.

About

A faster alternative for pbts from protobuf.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •