{"id":18821640,"url":"https://github.com/octu0/bp","last_synced_at":"2026-05-04T14:44:52.696Z","repository":{"id":41972822,"uuid":"285053424","full_name":"octu0/bp","owner":"octu0","description":"bytes.Buffer/Byte/image.RGBA/bufio.Reader/bufio.Writer/*time.Ticker/*time.Timer pool","archived":false,"fork":false,"pushed_at":"2023-02-26T07:03:00.000Z","size":87,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-30T03:43:24.146Z","etag":null,"topics":["buffer","buffer-pool","bufio","bytes","golang","pool","reader","rgba","ticker","timer"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/octu0/bp","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/octu0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-04T17:36:05.000Z","updated_at":"2023-03-07T07:15:49.000Z","dependencies_parsed_at":"2022-08-12T01:01:11.736Z","dependency_job_id":null,"html_url":"https://github.com/octu0/bp","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fbp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fbp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fbp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fbp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/octu0","download_url":"https://codeload.github.com/octu0/bp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239758900,"owners_count":19692041,"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":["buffer","buffer-pool","bufio","bytes","golang","pool","reader","rgba","ticker","timer"],"created_at":"2024-11-08T00:45:00.110Z","updated_at":"2026-01-18T09:30:17.914Z","avatar_url":"https://github.com/octu0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `bp`\n\n[![Apache License](https://img.shields.io/github/license/octu0/bp)](https://github.com/octu0/bp/blob/master/LICENSE)\n[![GoDoc](https://godoc.org/github.com/octu0/bp?status.svg)](https://godoc.org/github.com/octu0/bp)\n[![Go Report Card](https://goreportcard.com/badge/github.com/octu0/bp)](https://goreportcard.com/report/github.com/octu0/bp)\n[![Releases](https://img.shields.io/github/v/release/octu0/bp)](https://github.com/octu0/bp/releases)\n\n`bp` implements buffer pool of various objects such as byte array (`[]byte`) or [*bytes.Buffer](http://golang.org/pkg/bytes/#Buffer) / [*image.RGBA](https://golang.org/pkg/image/#RGBA) and [*bufio.Reader](https://golang.org/pkg/bufio/#Reader).  \nIt is inspired by [bpool](https://github.com/oxtoacart/bpool) and its many features are similar.\n\n`bp` provides the following pool types\n- `bp.BufferPool` which provides fixed-size pool of [*bytes.Buffers](http://golang.org/pkg/bytes/#Buffer)\n- `bp.BytePool` which provides fixed-size pool of `[]byte` slice \n- `bp.MmapBytePool` Same as BytePool, but uses mmap to allocate the slices\n- `bp.BufioReaderPool` which provides fixed-size pool of [*bufio.Reader](https://golang.org/pkg/bufio/#Reader)\n- `bp.BufioWriterPool` which provides fixed-size pool of [*bufio.Writer](https://golang.org/pkg/bufio/#Writer)\n- `bp.ImageRGBAPool` which provides fixed-size pool of [*image.RGBA](https://golang.org/pkg/image/#RGBA) \n- `bp.ImageYCbCrPool` which provides fixed-size pool of [*image.YCbCr](https://golang.org/pkg/image/#YCbCr) \n- `bp.CopyIOPool` which provides fixed-size pool of [io.CopyBuffer](https://golang.org/pkg/io#CopyBuffer) and [io.ReadAll](https://golang.org/pkg/io#ReadAll)\n- `bp.TickerPool` which provides fixed-size pool of [*time.Ticker](https://golang.org/pkg/time#Ticker)\n- `bp.TimerPool` which provides fixed-size pool of [*time.Timer](https://golang.org/pkg/time#Timer)\n\nIt also provides a MultiPool to bundle multiple pools:\n\n- MultiBytePool\n- MultiMmapBytePool\n- MultiBufferPool\n- MultiImageRGBAPool\n- MultiImageYCbCrPool\n\nIn addition, `bp` provides an easy to manipulate object interface to prevent forgetting to put it back into the pool\n\n- `bp.ByteRef`\n- `bp.BufferRef`\n- `bp.BufioReaderRef`\n- `bp.BufioWriterRef`\n- `bp.ImageRGBARef`\n- `bp.ImageYCbCrRef`\n\n## Installation\n\n```bash\ngo get github.com/octu0/bp\n```\n\n## Example\n\nHere's a quick example for using `bp.BufferPool`. We create a pool of the desired size, call the `Get()` method to obtain a buffer for use, and call `Put(buf)` to return the buffer to the pool.\n\n```go\nvar (\n  bufpool := bp.NewBufferPool(1000, 128) // capacity 1000 items, each buffer initial 128 Byte pre-sized\n)\n\nfunc main() {\n  // get buffer from pool\n  buf := bufpool.Get()\n  ...\n  ...\n  // return buffer to pool\n  bufpool.Put(buf)\n}\n```\n\n# Benchmark\n\n## `bytes.Buffer`: sync.Pool vs BufferPool\n\n```bash\n$ go test -bench=BenchmarkBufferPool -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkBufferPool/default/8-8         \t 1608904\t       768.9 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkBufferPool/default/4096-8      \t 1421576\t       791.1 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkBufferPool/syncpool/8-8        \t 1584180\t       743.3 ns/op\t      48 B/op\t       1 allocs/op\nBenchmarkBufferPool/syncpool/4096-8     \t 1505594\t       798.4 ns/op\t      48 B/op\t       1 allocs/op\nBenchmarkBufferPool/bufferpool/8-8      \t 1439310\t       917.2 ns/op\t      48 B/op\t       1 allocs/op\nBenchmarkBufferPool/bufferpool/4096-8   \t 1225413\t       967.4 ns/op\t      48 B/op\t       1 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t12.309s\n```\n\n## `[]byte`: sync.Pool vs BytePool\n\n```bash\n$ go test -bench=BenchmarkBytePool -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkBytePool/default/8-8         \t 1827867\t       653.8 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkBytePool/default/4096-8      \t 1562638\t       788.3 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkBytePool/syncpool/8-8        \t 1643428\t       763.2 ns/op\t      48 B/op\t       2 allocs/op\nBenchmarkBytePool/syncpool/4096-8     \t 1586283\t       803.8 ns/op\t      48 B/op\t       2 allocs/op\nBenchmarkBytePool/bytepool/8-8        \t 1357020\t       904.1 ns/op\t      24 B/op\t       1 allocs/op\nBenchmarkBytePool/bytepool/4096-8     \t 1359921\t       846.6 ns/op\t      24 B/op\t       1 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t12.105s\n```\n\n## `bufio.Reader`: sync.Pool vs BufioReaderPool\n\n```bash\n$ go test -bench=BenchmarkBufioReaderPool -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkBufioReaderPool/default/8-8         \t 1000000\t      1120 ns/op\t    1056 B/op\t       3 allocs/op\nBenchmarkBufioReaderPool/default/4096-8      \t  803418\t      1542 ns/op\t    5136 B/op\t       3 allocs/op\nBenchmarkBufioReaderPool/syncpool/8-8        \t 1000000\t      1102 ns/op\t    1048 B/op\t       2 allocs/op\nBenchmarkBufioReaderPool/syncpool/4096-8     \t 1000000\t      1110 ns/op\t    1051 B/op\t       2 allocs/op\nBenchmarkBufioReaderPool/bufiopool/8-8       \t 1000000\t      1290 ns/op\t    1160 B/op\t       4 allocs/op\nBenchmarkBufioReaderPool/bufiopool/4096-8    \t  918162\t      1279 ns/op\t    1048 B/op\t       2 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t7.147s\n```\n\n## `image.RGBA`: sync.Pool vs `ImageRGBAPool`\n\n```bash\n$ go test -bench=BenchmarkImageRGBAPool -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkImageRGBAPool/default/360-8         \t   31308\t     36206 ns/op\t  925814 B/op\t       3 allocs/op\nBenchmarkImageRGBAPool/default/1080-8        \t    4639\t    821211 ns/op\t 8282518 B/op\t       3 allocs/op\nBenchmarkImageRGBAPool/syncpool/360-8        \t 1657608\t       684.7 ns/op\t      20 B/op\t       1 allocs/op\nBenchmarkImageRGBAPool/syncpool/1080-8       \t 1635321\t       696.2 ns/op\t      56 B/op\t       1 allocs/op\nBenchmarkImageRGBAPool/imagepool/360-8       \t 1000000\t      1190 ns/op\t     151 B/op\t       3 allocs/op\nBenchmarkImageRGBAPool/imagepool/1080-8      \t 1000000\t      1105 ns/op\t     151 B/op\t       3 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t11.502s\n```\n\n## io.Copy vs CopyIOPool.Copy Benchmark\n\nCopyIOPool.Copy to reduce allocation of [io.Copy](https://golang.org/pkg/io/#Copy)\n\n```bash\n$ go test -bench=BenchmarkIoCopy -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkIoCopy-8                \t  461892\t      2637 ns/op\t   32816 B/op\t       3 allocs/op\nBenchmarkIoCopyPoolDefault-8     \t  619404\t      1982 ns/op\t   16608 B/op\t       7 allocs/op\nBenchmarkIoCopyPoolFixedSize-8   \t 2858724\t       410.9 ns/op\t      48 B/op\t       2 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t4.126s\n```\n\n## ioutil.ReadAll vs CopyIOPool.ReadAll Benchmark\n\nsimilarly, CopyIOPool.ReadAll reduces allocation of [io.ReadAll](https://golang.org/pkg/io#ReadAll)\n\n```bash\n$ go test -bench=BenchmarkIoReadAll -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkIoReadAllIoUtil-8          \t    2628\t    455815 ns/op\t 5862972 B/op\t      30 allocs/op\nBenchmarkIoReadAllPoolDefault-8     \t    3057\t    378599 ns/op\t 4063444 B/op\t      13 allocs/op\nBenchmarkIoReadAllPoolFixedSize-8   \t    3180\t    378923 ns/op\t 4046892 B/op\t       8 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t3.718s\n```\n\n## `*time.Ticker`: sync.Pool vs `TickerPool`\n\n```bash\n$ go test -bench=BenchmarkTickerPool -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkTickerPool/default-8         \t  114298\t     10731 ns/op\t     224 B/op\t       4 allocs/op\nBenchmarkTickerPool/syncpool-8        \t  110748\t     10863 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkTickerPool/pool-8            \t  110414\t     10867 ns/op\t      32 B/op\t       1 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t3.994s\n```\n\n## `*time.Timer`: sync.Pool vs `TimerPool`\n\n```bash\n$ go test -bench=BenchmarkTimerPool -benchmem ./\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/bp\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkTimerPool/default-8         \t  115437\t     10889 ns/op\t     224 B/op\t       4 allocs/op\nBenchmarkTimerPool/syncpool-8        \t  107302\t     11099 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkTimerPool/pool-8            \t  106790\t     11061 ns/op\t      32 B/op\t       1 allocs/op\nPASS\nok  \tgithub.com/octu0/bp\t4.002s\n```\n\n## License\n\nApache 2.0, see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fbp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctu0%2Fbp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fbp/lists"}