refactor: only init span cache when enable (#30)
A faster Protobuf serializer & deserializer.
Attention
go install github.com/cloudwego/fastpb/protoc-gen-fastpb@latest
Refer to examples, use in two steps:
Using the command line tool to generate code:
protoc --go_out=. \ --fastpb_out=. \ ${your_idl}.proto or protoc --go_opt=paths=source_relative --go_out=. \ --fastpb_opt=paths=source_relative --fastpb_out=. \ ${your_idl}.proto
Encoding and Decoding must use fastpb’s API, shown as demo:
package examples import ( "github.com/cloudwego/fastpb" ) // Marshal . func Marshal(msg fastpb.Writer) []byte { // TODO: buffer can be reused. buf := make([]byte, msg.Size()) msg.FastWrite(buf) return buf } // Unmarshal . func Unmarshal(buf []byte, msg fastpb.Reader) error { _, err := fastpb.ReadMessage(buf, int8(fastpb.SkipTypeCheck), msg) return err }
goos: linux goarch: amd64 pkg: github.com/cloudwego/fastpb/benchmark cpu: Intel(R) Xeon(R) Gold 5118 CPU @ 2.30GHz
Benchmarks have compared golang/protobuf (referred to as _golang) and fastpb here.
_golang
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
Fastpb
A faster Protobuf serializer & deserializer.
Attention
Install
Usage
Refer to examples, use in two steps:
Step 1: Generate Code
Using the command line tool to generate code:
Step 2: Codec Message
Encoding and Decoding must use fastpb’s API, shown as demo:
Performance
Benchmarks have compared golang/protobuf (referred to as
_golang) and fastpb here.Marshal
Unmarshal