The Go language community is discussing a new proposal called “arena”.
According to the proposal, “Go arena” is used to optimize memory allocation. arena is a method of allocating a set of memory objects from contiguous memory regions, with the advantage that allocating objects from arena is generally more efficient than general memory allocation. More importantly, objects in arena can be released all at once with minimal memory management or garbage collection overhead.
In general, arena is not implemented in programming languages that have garbage collection because the operations they use to explicitly free arena memory are unsafe and therefore do not conform to garbage collection semantics. However, this proposed implementation uses dynamic checks to ensure that arena operations are safe. It also guarantees that if an arena operation is unsafe, the program will terminate before any incorrect behavior occurs. The Go team has now implemented and used arena internally at Google, and the results show that it saves up to 15% of CPU and memory usage for many large applications, mainly due to reduced garbage collection CPU time and heap memory usage.
Proposal Introduction
Add a new arena
package to the Go standard library. The arena
package can be used to allocate any number of arena’s, any type of object can be allocated from the arena’s memory, and the arena will automatically grow in size as needed. When all objects in an arena are no longer in use, the arena can be explicitly freed to efficiently reclaim its memory without the need for the usual garbage collection operations. We require this implementation to provide safety checks so that if an arena operation is unsafe, the program will terminate before any incorrect behavior occurs. For maximum flexibility, the API is able to allocate any type of object and slice, including types that can be generated at runtime through reflection.
Proposal API.
|
|
arena Usage examples.