Documentation
¶
Index ¶
Constants ¶
const ( MinArenaSize = 512 MaxArenaSize = 4096 )
The size of a string arena is bounded, but not strictly by [min, max]:
- Attempting to set a capacity below MinArenaSize will have no effect as beneath this limit it is not worth it. Calls to String with a capacity below this boundary will simply allocate.
- An arena WILL be capped at MaxArenaSize.
const ArenaPayloadFactor = 4
ArenaPayloadFactor is the ratio at which we size string arenas to the payload (clamped by StringArenaMin/Max)
We limit arenas to 4k but smaller payloads likely don't need it, so we size down (somewhat arbitrarily) until we hit the 512-byte floor at which we just don't arena.
Variables ¶
This section is empty.
Functions ¶
func ReadPayloadBlob ¶ added in v1.27.7
ReadPayloadBlob consumes the given reader into a buffer that does not come from (and will never be returned to) a pool, sizing it from contentLength when that is known and within bounds.
Types ¶
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack is a generic slice-backed stack pre-allocated to avoid growth allocations for typical serde nesting depths.
func (*Stack[T]) Reset ¶
func (s *Stack[T]) Reset()
Reset clears the stack while retaining allocated capacity.
type StringArena ¶ added in v1.27.7
type StringArena struct {
// contains filtered or unexported fields
}
StringArena batches many small string allocations into one block.
You MUST call Reset with the desired capacity before use. Failure to do so will mean any calls to String will simply allocate and you won't get the performance benefit of the arena.
func (*StringArena) Reset ¶ added in v1.27.7
func (a *StringArena) Reset(cap int)
Reset prepares the arena for a new document, sizing its next block to cap.
func (*StringArena) String ¶ added in v1.27.7
func (a *StringArena) String(b []byte) string
String attempts to intern a copy of b in the arena, returning a string slice for it.
If the arena is at capacity, it will just allocate a new string.