{"id":19674714,"url":"https://github.com/cloudwego/fastpb","last_synced_at":"2025-04-04T10:07:36.545Z","repository":{"id":55061230,"uuid":"513505572","full_name":"cloudwego/fastpb","owner":"cloudwego","description":"A faster Protobuf serializer \u0026 deserializer.","archived":false,"fork":false,"pushed_at":"2024-08-19T23:28:40.000Z","size":110,"stargazers_count":91,"open_issues_count":8,"forks_count":9,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-28T09:05:38.972Z","etag":null,"topics":["deserializer","serializer"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudwego.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-13T12:05:48.000Z","updated_at":"2025-03-21T14:41:54.000Z","dependencies_parsed_at":"2024-06-03T04:36:53.383Z","dependency_job_id":"5ee42145-fc87-4cce-9329-8a118b4a5daf","html_url":"https://github.com/cloudwego/fastpb","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"cloudwego/.github","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudwego%2Ffastpb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudwego%2Ffastpb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudwego%2Ffastpb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudwego%2Ffastpb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudwego","download_url":"https://codeload.github.com/cloudwego/fastpb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157047,"owners_count":20893202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deserializer","serializer"],"created_at":"2024-11-11T17:19:31.177Z","updated_at":"2025-04-04T10:07:36.510Z","avatar_url":"https://github.com/cloudwego.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Fastpb\n\nA faster Protobuf serializer \u0026 deserializer.\n\n**Attention**\n\n* only proto3 is supported now.\n* known-types(any, api, duration...) is not supported now.\n\n## Install\n\n```shell\ngo install github.com/cloudwego/fastpb/protoc-gen-fastpb@latest\n```\n\n## Usage\n\nRefer to [examples][examples], use in two steps:\n\n1. use fastpb to generate code. ([refer here][gen_sh])\n2. use fastpb API to marshal/unmarshal. ([refer here][demo])\n\n### Step 1: Generate Code\n\nUsing the command line tool to generate code:\n\n```shell\nprotoc --go_out=. \\\n  --fastpb_out=. \\\n  ${your_idl}.proto\n\nor\n\nprotoc --go_opt=paths=source_relative --go_out=. \\\n  --fastpb_opt=paths=source_relative --fastpb_out=. \\\n   ${your_idl}.proto\n```\n\n### Step 2: Codec Message\n\nEncoding and Decoding must use fastpb's API, shown as [demo][demo]:\n\n```go\npackage examples\n\nimport (\n\t\"github.com/cloudwego/fastpb\"\n)\n\n// Marshal .\nfunc Marshal(msg fastpb.Writer) []byte {\n\t// TODO: buffer can be reused.\n\tbuf := make([]byte, msg.Size())\n\n\tmsg.FastWrite(buf)\n\treturn buf\n}\n\n// Unmarshal .\nfunc Unmarshal(buf []byte, msg fastpb.Reader) error {\n\t_, err := fastpb.ReadMessage(buf, int8(fastpb.SkipTypeCheck), msg)\n\treturn err\n}\n```\n\n## Performance\n\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/cloudwego/fastpb/benchmark\ncpu: Intel(R) Xeon(R) Gold 5118 CPU @ 2.30GHz\n```\n\nBenchmarks have compared [golang/protobuf][golang] (referred to as `_golang`) and [fastpb][fastpb] here.\n\n### Marshal\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_number_golang-48\u003c/td\u003e\u003ctd\u003e 375.2 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e    96 B/op \u003c/td\u003e\u003ctd\u003e ~        \u003c/td\u003e\u003ctd\u003e   1 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_number_fastpb-48\u003c/td\u003e\u003ctd\u003e 145.7 ns/op \u003c/td\u003e\u003ctd\u003e -61.17% \u003c/td\u003e\u003ctd\u003e     0 B/op \u003c/td\u003e\u003ctd\u003e -100.00% \u003c/td\u003e\u003ctd\u003e   0 allocs/op \u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_string_golang-48\u003c/td\u003e\u003ctd\u003e  1010 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e  2304 B/op \u003c/td\u003e\u003ctd\u003e ~        \u003c/td\u003e\u003ctd\u003e   1 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_string_fastpb-48\u003c/td\u003e\u003ctd\u003e 58.57 ns/op \u003c/td\u003e\u003ctd\u003e -94.20% \u003c/td\u003e\u003ctd\u003e     0 B/op \u003c/td\u003e\u003ctd\u003e -100.00% \u003c/td\u003e\u003ctd\u003e   0 allocs/op \u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_list_golang-48  \u003c/td\u003e\u003ctd\u003e  8788 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e 18432 B/op \u003c/td\u003e\u003ctd\u003e ~        \u003c/td\u003e\u003ctd\u003e   1 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_list_fastpb-48  \u003c/td\u003e\u003ctd\u003e  3430 ns/op \u003c/td\u003e\u003ctd\u003e -60.97% \u003c/td\u003e\u003ctd\u003e     0 B/op \u003c/td\u003e\u003ctd\u003e -100.00% \u003c/td\u003e\u003ctd\u003e   0 allocs/op \u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_map_golang-48   \u003c/td\u003e\u003ctd\u003e 43497 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e 21680 B/op \u003c/td\u003e\u003ctd\u003e ~        \u003c/td\u003e\u003ctd\u003e 393 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_marshal_map_fastpb-48   \u003c/td\u003e\u003ctd\u003e  5951 ns/op \u003c/td\u003e\u003ctd\u003e -86.32% \u003c/td\u003e\u003ctd\u003e     0 B/op \u003c/td\u003e\u003ctd\u003e -100.00% \u003c/td\u003e\u003ctd\u003e   0 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n### Unmarshal\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_number_golang-48\u003c/td\u003e\u003ctd\u003e 497.1 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e   144 B/op \u003c/td\u003e\u003ctd\u003e   1 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_number_fastpb-48\u003c/td\u003e\u003ctd\u003e 431.6 ns/op \u003c/td\u003e\u003ctd\u003e -13.18% \u003c/td\u003e\u003ctd\u003e   144 B/op \u003c/td\u003e\u003ctd\u003e   1 allocs/op \u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_string_golang-48\u003c/td\u003e\u003ctd\u003e 939.7 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e  2128 B/op \u003c/td\u003e\u003ctd\u003e   3 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_string_fastpb-48\u003c/td\u003e\u003ctd\u003e 668.4 ns/op \u003c/td\u003e\u003ctd\u003e -28.87% \u003c/td\u003e\u003ctd\u003e  2128 B/op \u003c/td\u003e\u003ctd\u003e   3 allocs/op \u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_list_golang-48  \u003c/td\u003e\u003ctd\u003e 12527 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e 20296 B/op \u003c/td\u003e\u003ctd\u003e  99 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_list_fastpb-48  \u003c/td\u003e\u003ctd\u003e 12593 ns/op \u003c/td\u003e\u003ctd\u003e +0.53%  \u003c/td\u003e\u003ctd\u003e 20296 B/op \u003c/td\u003e\u003ctd\u003e  99 allocs/op \u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_map_golang-48   \u003c/td\u003e\u003ctd\u003e 49868 ns/op \u003c/td\u003e\u003ctd\u003e ~       \u003c/td\u003e\u003ctd\u003e 24226 B/op \u003c/td\u003e\u003ctd\u003e 426 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eBenchmark_unmarshal_map_fastpb-48   \u003c/td\u003e\u003ctd\u003e 21213 ns/op \u003c/td\u003e\u003ctd\u003e -57.46% \u003c/td\u003e\u003ctd\u003e 21467 B/op \u003c/td\u003e\u003ctd\u003e  61 allocs/op \u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\n[fastpb]: https://github.com/cloudwego/fastpb\n\n[examples]: https://github.com/cloudwego/fastpb/tree/main/examples\n\n[demo]: https://github.com/cloudwego/fastpb/blob/main/examples/demo.go\n\n[gen_sh]: https://github.com/cloudwego/fastpb/blob/main/examples/gen_code.sh\n\n[golang]: https://github.com/golang/protobuf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudwego%2Ffastpb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudwego%2Ffastpb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudwego%2Ffastpb/lists"}