{"id":34514186,"url":"https://github.com/koykov/cbytebuf","last_synced_at":"2025-12-24T04:18:27.991Z","repository":{"id":57571860,"uuid":"225060764","full_name":"koykov/cbytebuf","owner":"koykov","description":"Byte buffer with zero alloc on grow","archived":false,"fork":false,"pushed_at":"2024-06-30T20:06:10.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-12T05:02:45.982Z","etag":null,"topics":["bytebuffer","cbyte","minimize-allocs","minimize-gc"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koykov.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-30T19:34:20.000Z","updated_at":"2024-06-30T20:05:55.000Z","dependencies_parsed_at":"2023-12-11T22:58:43.638Z","dependency_job_id":"d67db7b4-a2bb-41d0-8bcd-2d2e6e35e7ec","html_url":"https://github.com/koykov/cbytebuf","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/koykov/cbytebuf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koykov%2Fcbytebuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koykov%2Fcbytebuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koykov%2Fcbytebuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koykov%2Fcbytebuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koykov","download_url":"https://codeload.github.com/koykov/cbytebuf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koykov%2Fcbytebuf/sbom","scorecard":{"id":568746,"data":{"date":"2025-08-11","repo":{"name":"github.com/koykov/cbytebuf","commit":"3c07820505074d30355292a25fbd9c1898b46f06"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license.md:0","Info: FSF or OSI recognized license: MIT License: license.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 18 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T15:44:08.958Z","repository_id":57571860,"created_at":"2025-08-20T15:44:08.958Z","updated_at":"2025-08-20T15:44:08.958Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27994571,"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","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bytebuffer","cbyte","minimize-allocs","minimize-gc"],"created_at":"2025-12-24T04:18:27.450Z","updated_at":"2025-12-24T04:18:27.978Z","avatar_url":"https://github.com/koykov.png","language":"Go","readme":"# CbyteBuf\n\nAlloc-free replacement for [bytes.Buffer](https://golang.org/pkg/bytes/#Buffer) based on [cbyte](https://github.com/koykov/cbyte).\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/koykov/cbytebuf\"\n)\n\nfunc main() {\n\tbuf := cbytebuf.NewCByteBuf()\n\tdefer buf.Release()\n\t_, _ = buf.WriteString(\"foo \")\n\t_, _ = buf.WriteString(\"bar \")\n\t// ...\n\t_, _ = buf.WriteString(\"end.\")\n\tfmt.Println(buf.String()) // \"foo bar ... end.\"\n}\n```\n\nNo escapes to heap:\n\n```bash\n$ go build -gcflags '-m' example.go \n# command-line-arguments\nexample/example.go:9:9: inlining call to cbytebuf.NewCByteBuf\nexample/example.go:9:9: main \u0026cbytebuf.b·2 does not escape\n```\n\nSee [test file](https://github.com/koykov/cbytebuf/blob/master/cbytebuf_test.go) for more examples and benchmarks for number of allocations.\n\n## How it works\n\nThis package was inspired by article [Allocation efficiency in high-performance Go services](https://segment.com/blog/allocation-efficiency-in-high-performance-go-services/).\nPlease read it before continue.\n\nIf you will use a lot of bytes.Buffer (or any analogues) you may notice that GC pressure will increase during the time\neven if you use sync.Pool. This occurs since all slices in the pools (or any storage) checks by GC during mark phase.\n\nThe main approach of CbyteBuf is to avoid using any references and pointers inside it and, consecutive, avoid escapes to heap.\nIn fact the instance of CbyteBuf contains only [SliceHeader](https://golang.org/pkg/reflect/#SliceHeader) and temporary int variable - one uintptr and three integers in result.\nAs result any new instance of CBB allocates in stack instead of heap.\nIn fact allocations in heap occurs, but they produces by [cbyte](https://github.com/koykov/cbyte) and GC doesn't know nothing about them.\n\nWe've experienced increasing in more than 2 times the intervals between GC cycles, that is very good for our project. Also we noticed decreasing of GC CPU usage in ~3 times.\n\n## Benchmarks\n\n```\nBenchmarkCByteBuf_Write-8          \t  345268\t      3602 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkCByteBuf_WriteLong-8      \t    2622\t    439151 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkCByteBuf_AppendBytes-8    \t 1373740\t       870 ns/op\t     896 B/op\t       1 allocs/op\nBenchmarkCByteBuf_AppendString-8   \t 1342476\t       869 ns/op\t     896 B/op\t       1 allocs/op\nBenchmarkLBPool-8                  \t11660017\t       101 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkPool-8                    \t 5501479\t       205 ns/op\t       0 B/op\t       0 allocs/op\n```\n\nAlso you can see more comparison benchmarks in [versus](https://github.com/koykov/versus/tree/master/cbytebuf) project:\n```\nBenchmarkByteArray_Append-8             \t  767320\t      1449 ns/op\t    2040 B/op\t       8 allocs/op\nBenchmarkByteArray_AppendLong-8         \t    1557\t    754013 ns/op\t 4646288 B/op\t      25 allocs/op\nBenchmarkByteBufferNative_Write-8       \t  517546\t      2376 ns/op\t    2416 B/op\t       5 allocs/op\nBenchmarkByteBufferNative_WriteLong-8   \t    3441\t    346512 ns/op\t 1646722 B/op\t      10 allocs/op\nBenchmarkByteBufferPool_Write-8         \t  904567\t      1335 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkByteBufferPool_WriteLong-8     \t    1555\t    754847 ns/op\t 4667398 B/op\t      29 allocs/op\nBenchmarkCByteBuf_Write-8               \t  380574\t      3171 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkCByteBuf_WriteLong-8           \t    2631\t    454779 ns/op\t       0 B/op\t       0 allocs/op\n```\n\nAs you can see, CbyteBuf is slowest than any byte buffer or byte slice when writing short pieces of data, but has good speed for long writes.\nInteresting that long writes is more faster that using append().\n\nAnyway it's acceptable cost since it produces zero allocations even if you doesn't use pools. But I recommend to use it together with pool since it reduces amount of CGO calls in [cbyte](https://github.com/koykov/cbyte).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoykov%2Fcbytebuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoykov%2Fcbytebuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoykov%2Fcbytebuf/lists"}