{"id":26770822,"url":"https://github.com/limpo1989/arena","last_synced_at":"2025-08-18T19:04:02.821Z","repository":{"id":282003719,"uuid":"947010615","full_name":"limpo1989/arena","owner":"limpo1989","description":"A high-performance memory allocator for Go that reduces garbage collection (GC) overhead by managing object lifetimes explicitly.","archived":false,"fork":false,"pushed_at":"2025-03-24T10:36:42.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-18T19:03:14.910Z","etag":null,"topics":["arena","arena-allocator"],"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/limpo1989.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-12T02:38:20.000Z","updated_at":"2025-03-24T10:36:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ed60b5b-521f-44da-8b22-0b6740a52311","html_url":"https://github.com/limpo1989/arena","commit_stats":null,"previous_names":["limpo1989/arena"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/limpo1989/arena","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limpo1989%2Farena","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limpo1989%2Farena/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limpo1989%2Farena/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limpo1989%2Farena/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/limpo1989","download_url":"https://codeload.github.com/limpo1989/arena/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limpo1989%2Farena/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271043504,"owners_count":24689767,"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-08-18T02:00:08.743Z","response_time":89,"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":["arena","arena-allocator"],"created_at":"2025-03-28T23:16:42.921Z","updated_at":"2025-08-18T19:04:02.763Z","avatar_url":"https://github.com/limpo1989.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arena Memory Allocator\n[![Go Reference](https://pkg.go.dev/badge/github.com/limpo1989/arena.svg)](https://pkg.go.dev/github.com/limpo1989/arena)\n\nA high-performance memory allocator for Go that reduces garbage collection (GC) overhead by managing object lifetimes explicitly.\n\n## Features\n- **Reduces GC Pressure**: Allocates objects in contiguous chunks, minimizing GC scans.\n- **Zero-Allocation APIs**: Methods like `Malloc`, `New`, and `NewSlice` avoid heap allocations.\n- **Thread Safety**: Optional spinlock-based synchronization.\n- **Customizable**: Configure chunk sizes, memory sources, and pooling behavior.\n- **Rich Utilities**: Includes type-safe vectors (`Vector[T]`) and deep-copy helpers.\n\n## Use Cases\n- High-throughput services with frequent small object allocations.\n- Long-lived objects that benefit from bulk deallocation.\n- Latency-sensitive applications needing predictable GC behavior.\n\n## Installation\n```bash\ngo get github.com/limpo1989/arena\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/limpo1989/arena\"\n)\n\nfunc main() {\n\tar := arena.NewArena()\n\tdefer ar.Reset()\n\n\t// Allocate primitives\n\tnum := arena.New[int](ar)\n\t*num = 42\n\tfmt.Println(\"print num:\", *num)\n\n\t// Allocate slices\n\tslice := arena.NewSlice[string](ar, 0, 10)\n\tslice = arena.Append(ar, slice, \"hello\", \"world\")\n\tfmt.Println(\"print slice:\", slice)\n\n\t// Use vectors\n\tvec := arena.NewVector[int](ar, 8)\n\tvec.Append(1, 2, 3)\n\tfmt.Println(\"print vec:\", vec.At(0), vec.At(1), vec.At(2))\n}\n\n// Output:\n// print num: 42\n// print slice: [hello world]\n// print vec: 1 2 3\n```\n\n## Performance\n\nArena reduces GC pauses by:\n1. Bulk Allocation: Objects are grouped in chunks, decreasing GC scan count.\n2. Lifetime Control: Allocations are freed together via Reset().\n3. Reduced Fragmentation: Chunk reuse minimizes heap fragmentation.\n\n### Benchmark (vs. Go heap):\n\n```\nTestHeapLargeObjects    Heap GC took time: 224.9326ms, living objects: 25001072\nTestArenaLargeObjects   Arena GC took time: 14.0116ms, living objects: 16819\n```\n\n## Caveats\n* Manual Management: You must call Free or Reset to reclaim memory.\n* No GC Integration: Arena-allocated objects are ignored by Go's GC.\n* Pointer Safety: Mixing Arena and heap pointers may cause leaks/errors.\n* Unsupported Types: map, channel, func\n\n### Bad Case\n\n**Mixing Arena and heap pointers**\n\n```go\nfunc main() {\n    ar := NewArena()\n    defer ar.Reset()\n    \n    type subject struct {\n        id  int32\n        age *int32\n    }\n    \n    p := New[subject](ar)\n    p.age = new(int32) // Bad：store heap pointer\n    *p.age = 100\n    \n    // You can setting a finalizer, it is possible to observe that the heap memory pointer will be reclaimed before the Arena ends\n    //\n    runtime.SetFinalizer(p.age, func (p *int32) {\n        fmt.Println(\"subject.age released\")\n    })\n    \n    runtime.GC()\n    fmt.Println(\"gc finished 1\")\n    runtime.GC()\n    fmt.Println(\"gc finished 2\")\n    \n    // Undefined access, in fact, this part of memory has already been reclaimed by GC.\n    // Although it might be possible to access it here, it will result in undefined behavior\n    //\n    *p.age = 99 // Undefined access \n}\n```\n\n### License\n\nThe `arena` is released under version 2.0 of the Apache License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimpo1989%2Farena","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimpo1989%2Farena","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimpo1989%2Farena/lists"}