TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A new ProtoBuf generator for Go

296 pointsby tanokualmost 4 years ago

9 comments

jupp0ralmost 4 years ago
Using CPU utilization as a performance metric can be extremely misleading. My favorite article on the subject is from Brendan Gregg:<p><a href="http:&#x2F;&#x2F;www.brendangregg.com&#x2F;blog&#x2F;2017-05-09&#x2F;cpu-utilization-is-wrong.html" rel="nofollow">http:&#x2F;&#x2F;www.brendangregg.com&#x2F;blog&#x2F;2017-05-09&#x2F;cpu-utilization-...</a><p>A much better way to test the influence of the new compiler would be to test the actual throughput at which saturation is achieved (which is what the benchmark in the C++ grpc library measure to assess their performance).
评论 #27386962 未加载
评论 #27386281 未加载
jen20almost 4 years ago
I&#x27;m not sure that the phrasing in the article is particularly fair:<p>&gt; The maintainers of Gogo, understandably, were not up to the gigantic task.<p>I&#x27;m 99% sure they are &quot;up to&quot; (as in &quot;capable of&quot;) doing so, they are just not &quot;up for&quot; it (as in, &quot;will not do it&quot;).
评论 #27386150 未加载
评论 #27387026 未加载
评论 #27386658 未加载
jzelinskiealmost 4 years ago
I hadn&#x27;t realized that Gogo was in such a bad spot with the upstream Go protobuf changes. There was lots of drama when the changes were made and I guess that overshadowed any optics I had on Gogo.<p>Making vtprotobuf an additional protoc plugin seems like the Right Thing™, although it&#x27;s a shame how complicated protoc commands end up becoming for mature projects. I&#x27;m pretty tempted to port Authzed over to this and run some benchmarks -- our entire service requires e2e latency under 20ms, so every little bit counts. The biggest performance win is likely just having an unintrusive interface for pooling allocated protos.
评论 #27385399 未加载
评论 #27385553 未加载
sa46almost 4 years ago
Funny timing, I&#x27;ve just written most of a TypeScript generator for protobufs. I learned about some fun corners of protobufs I didn&#x27;t expect trying to pass the protouf conformance tests [1] (which this one passes, that&#x27;s no mean feat!).<p>- If you write the same message multiple times, protobuf implementations should merge fields with a last write wins policy (repeated fields are concatenated). This includes messages in oneofs.<p>- For a boolean array, you&#x27;re better off using a packed, repeated int64 (if wire size matters a lot). Protobuf bools use varint encoding meaning you need at least 2 bytes for every boolean, 1+ for the tag and type and 1 byte for the 0 or 1 value. With a repeated int64, you&#x27;d encode the tag and length in 2 varints, and then you get 64 bools per 8 bytes.<p>- Fun trivia: Varints take up a max of 10 bytes but could be implemented in 9 bytes. You get 7 bits per varint byte, so 9 bytes gets you 63 bits. Then you could use the most significant bit of the last byte to indicate if the last bit is 0 or 1. Learned by reading the Go varint implementation [2].<p>- Messages can be recursive. This is easy if you represent messages as pointers since you can use nil. It&#x27;s a fair bit harder if you want to always use a value object for each nested message since you need to break cycles by marking fields as `T | undefined` to avoid blowing the stack. Figuring out the minimal number of fields to break cycles is an NP hard problem called the minimum feedback arc set[3].<p>- If you&#x27;re writing a protobuf implementation, the conformance tests are a really nice way to check that you&#x27;ve done a good job. Be wary of implementations that don&#x27;t implement the conformance tests.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;protocolbuffers&#x2F;protobuf&#x2F;tree&#x2F;master&#x2F;conformance" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;protocolbuffers&#x2F;protobuf&#x2F;tree&#x2F;master&#x2F;conf...</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;blob&#x2F;master&#x2F;src&#x2F;encoding&#x2F;binary&#x2F;varint.go#L18" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;blob&#x2F;master&#x2F;src&#x2F;encoding&#x2F;binary...</a><p>[3]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Feedback_arc_set#Minimum_feedback_arc_set" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Feedback_arc_set#Minimum_feedb...</a>
评论 #27391746 未加载
shoefindortzalmost 4 years ago
&gt; Arenas are, however, unfeasible to implement in Go because it is a garbage collected language.<p>If you are willing to use cgo, google already implemented one for gapid.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;gapid&#x2F;tree&#x2F;master&#x2F;core&#x2F;memory&#x2F;arena" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;gapid&#x2F;tree&#x2F;master&#x2F;core&#x2F;memory&#x2F;aren...</a>
评论 #27385878 未加载
flakinessalmost 4 years ago
I wonder what Google is thinking about the v2 performance. It&#x27;s well known that protobuf processing is taxing heavy on their data center [1]. It&#x27;s hard to imagine they just leave it slow. Or do they?<p>[1] <a href="https:&#x2F;&#x2F;research.google&#x2F;pubs&#x2F;pub44271&#x2F;" rel="nofollow">https:&#x2F;&#x2F;research.google&#x2F;pubs&#x2F;pub44271&#x2F;</a>
评论 #27387510 未加载
gilgad13almost 4 years ago
Maybe I&#x27;m missing something, but my read of golang&#x2F;protobuf#364[1] was that part of the motivation for the re-organization in protobuf-go v2 was to allow for optimizations like gogoprotobuf to be developed without requiring a complete fork. I totally understand that the authors of gogoprotobuf do not have the time to re-architect their library to use these hooks, but best I can figure this generator does not use these hooks either. Instead it defines additional member functions, and wrappers that look for those specialized functions and fallback to the generic ones if not found.<p>For example, it looks like pooled decoders could be implemented by setting a custom unmarshaller through the ProtoMethods[2] API.<p>I wonder why not? Did the authors of the vtprotobuf extension not want to bite off that much work? Is the new API not sufficient to do what they want (thus failing some of the goals expressed in golang&#x2F;protobuf#364?<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;protobuf&#x2F;issues&#x2F;364" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;protobuf&#x2F;issues&#x2F;364</a><p>[2]: <a href="https:&#x2F;&#x2F;pkg.go.dev&#x2F;google.golang.org&#x2F;protobuf@v1.26.0&#x2F;reflect&#x2F;protoreflect#Message" rel="nofollow">https:&#x2F;&#x2F;pkg.go.dev&#x2F;google.golang.org&#x2F;protobuf@v1.26.0&#x2F;reflec...</a>
评论 #27387651 未加载
n0x1malmost 4 years ago
the biggest current problem with Go and ProtoBuf is swagger support when using it for API returns. Enums are not supported for example. The leniency of protojson can&#x27;t be used in other languages that built on top of the swagger docs.
PostThisTooFastalmost 4 years ago
Is there one for Kotlin yet? It&#x27;s pretty pathetic that Google&#x27;s own protocol lacks native support for its most popular operating system.
评论 #27385293 未加载
评论 #27386212 未加载
评论 #27391229 未加载