pool

package
v0.4.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package pool provides a size-class byte buffer pool that eliminates allocations on media-heavy hot paths (audio chunks, image tiles, video frames).

Under millions of concurrent LLM calls the GC cost of per-frame []byte allocations dominates. BytePool provides O(1) amortised Get/Put with no per-operation heap allocation.

Index

Constants

This section is empty.

Variables

View Source
var DefaultBytePool = NewBytePool()

DefaultBytePool is the process-wide byte pool. Providers and processors should use this unless they need isolation.

Functions

This section is empty.

Types

type BytePool

type BytePool struct {
	// contains filtered or unexported fields
}

BytePool is a size-class byte buffer pool.

Usage:

buf := pool.DefaultBytePool.Get(frameSize)
copy(buf, rawPayload)
// ... after consumer is done:
pool.DefaultBytePool.Put(buf)

func NewBytePool

func NewBytePool() *BytePool

NewBytePool creates a new BytePool with pre-allocated size classes.

func (*BytePool) Get

func (p *BytePool) Get(size int) []byte

Get returns a byte slice with len=size from the appropriate size class. The returned slice may have capacity > size.

func (*BytePool) Put

func (p *BytePool) Put(b []byte)

Put returns a byte slice to the pool. After Put, the caller must not reference the slice. Slices larger than the large class are dropped (GC collects them).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL