proxy.golang.org : github.com/bufbuild/hyperpb-go
Package hyperpb is a highly optimized dynamic message library for Protobuf or read-only workloads. It is designed to be a drop-in replacement for dynamicpb, protobuf-go's canonical solution for working with completely dynamic messages. hyperpb's parser is an efficient VM for a special instruction set, a variant of table-driven parsing (TDP), pioneered by the UPB project. Our parser is very fast, beating dynamicpb by 10x, and often beating protobuf-go's generated code by a factor of 2-3x, especially for workloads with many nested messages. The core conceit of hyperpb is that you must pre-compile a parser using hyperpb.CompileMessageDescriptor at runtime, much like regular expressions require that you use regexp.Compile them. Doing this allows hyperpb to run optimization passes on your message, and delaying it to runtime allows us to continuously improve layout optimizations, without making any source-breaking changes. For example, let's say that we want to compile a parser for some type baked into our binary, and parse some data with it. For example, let's say that we want to compile a parser for some type baked into our binary, and parse some data with it. Currently, hyperpb only supports manipulating messages through the reflection API; it shines best when you need write a very generic service that downloads types off the network and parses messages using those types, which forces you to use reflection. Mutation is currently not supported; any operation which would mutate an already-parsed message will panic. Which methods of Message panic is included in the documentation. hyperpb has a memory-reuse mechanism that side-steps the Go garbage collector for improved allocation latency. Shared is book-keeping state and resources shared by all messages resulting from the same parse. After the message goes out of scope, these resources are ordinarily reclaimed by the garbage collector. However, a Shared can be retained after its associated message goes away, allowing for re-use. Consider the following example of a request handler: Beware that msg must not outlive the call to Shared.Free; failure to do so will result in memory errors that Go cannot protect you from. `hyperpb` supports online PGO for squeezing extra performance out of the parser by optimizing the parser with knowledge of what the average message actually looks like. For example, using PGO, the parser can predict the expected size of repeated fields and allocate more intelligently. For example, suppose you have a corpus of messages for a particular type. You can build an optimized type, using that corpus as the profile, using `Type.Recompile`: hyperpb is experimental software, and the API may change drastically before v1. It currently implements all Protobuf language constructs. It does not implement mutation of parsed messages, however.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/bufbuild/hyperpb-go
Keywords:
grpc
, protobuf
, protoc
, protocol-buffers
License: Apache-2.0
Latest release: 18 days ago
First release: 18 days ago
Namespace: github.com/bufbuild
Stars: 178 on GitHub
Forks: 4 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 11 days ago