Hacker News new | ask | show | jobs
by hmillison 1421 days ago
I have used protobufs and grpc on the web before. Maybe this project is the magic bullet that makes it easy to do, but in the past that typescript support from Google and 3rd parties (improbable eng) was lacking and there was little interest in making simple changes to make it easier to use.

On top of that, the increase in JS shipped to user's due to the size of the generated protobuf objects was unacceptable for anything that cares about keeping their bundle size manageable. Have you done anything to address this issue?

2 comments

Not sure if it is a magic bullet, but it was definitely written by TypeScript developers, for TypeScript developers.

The generated TypeScript code is already pretty minimal because all serialization ops are implemented with reflection instead of generated code (which is only marginally slower than generated code in JS).

But you can also switch to generating JavaScript + TypeScript declaration files, which is truly minimal: JavaScript is an entire dynamic language, so we actually only generated a small snippet of metadata in the .js output, and create a class at run time with a function call. The generated typings (.d.ts) give you type safety, autocompletion in the IDE, and so on.

You can see the output here: https://github.com/bufbuild/protobuf-es/blob/main/packages/p...

The article specifically mentions that bundle sizes for grpc packages in the past were unacceptable and that they've made big improvements.
Ye, fwiw there is an example code size comparison here:

https://github.com/bufbuild/connect-web/blob/main/packages/c...

I'm sure someone will chime in on the implementation details, but hopefully others can give it a try with their projects!

That's great news! I missed that in my initial skim of the article.