pools

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package pools provides object pooling for reducing GC pressure.

This package contains various pool implementations for commonly allocated types in the graph database:

  • BytePool: Size-class based byte slice pooling
  • Uint64Pool: Pooling for uint64 slices (edge lists, IDs)
  • StringMapPool: Pooling for property maps
  • BufferBuilder: Efficient buffer construction with pooling

Index

Constants

View Source
const (
	TinySize   = 16    // For small keys, headers
	SmallSize  = 64    // For typical keys
	MediumSize = 256   // For small values, serialized data
	LargeSize  = 1024  // For larger values
	HugeSize   = 4096  // For batch operations
	MaxPool    = 65536 // Don't pool buffers larger than this
)

Buffer size classes for efficient reuse

Variables

This section is empty.

Functions

func GetBytes

func GetBytes(size int) []byte

GetBytes returns a byte slice from the default pool.

func GetBytesSized

func GetBytesSized(size int) []byte

GetBytesSized returns a byte slice with exact length from the default pool.

func GetStringMap

func GetStringMap() map[string]any

GetStringMap returns a string map from the default pool.

func GetUint64s

func GetUint64s(size int) []uint64

GetUint64s returns a uint64 slice from the default pool.

func PutBytes

func PutBytes(b []byte)

PutBytes returns a byte slice to the default pool.

func PutStringMap

func PutStringMap(m map[string]any)

PutStringMap returns a string map to the default pool.

func PutUint64s

func PutUint64s(s []uint64)

PutUint64s returns a uint64 slice to the default pool.

Types

type BufferBuilder

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

BufferBuilder provides a convenient way to build byte slices with pooling.

func NewBufferBuilder

func NewBufferBuilder(initialCap int) *BufferBuilder

NewBufferBuilder creates a new buffer builder with the given initial capacity.

func (*BufferBuilder) Bytes

func (b *BufferBuilder) Bytes() []byte

Bytes returns the built buffer. After calling Bytes, the builder should not be used.

func (*BufferBuilder) Len

func (b *BufferBuilder) Len() int

Len returns the current length of the buffer.

func (*BufferBuilder) Release

func (b *BufferBuilder) Release()

Release returns the buffer to the pool. After Release, the builder should not be used.

func (*BufferBuilder) Reset

func (b *BufferBuilder) Reset()

Reset resets the buffer for reuse.

func (*BufferBuilder) Write

func (b *BufferBuilder) Write(p []byte)

Write appends bytes to the buffer.

func (*BufferBuilder) WriteByte

func (b *BufferBuilder) WriteByte(c byte) error

WriteByte appends a single byte.

func (*BufferBuilder) WriteString

func (b *BufferBuilder) WriteString(s string)

WriteString appends a string.

func (*BufferBuilder) WriteUint32BE

func (b *BufferBuilder) WriteUint32BE(v uint32)

WriteUint32BE appends a uint32 in big-endian order.

func (*BufferBuilder) WriteUint64BE

func (b *BufferBuilder) WriteUint64BE(v uint64)

WriteUint64BE appends a uint64 in big-endian order.

type BytePool

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

BytePool provides size-class based pooling for byte slices. This reduces GC pressure by reusing buffers of appropriate sizes.

func NewBytePool

func NewBytePool() *BytePool

NewBytePool creates a new byte pool with pre-allocated buffers.

func (*BytePool) Get

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

Get returns a byte slice with at least the requested capacity. The returned slice has length 0 and the specified capacity.

func (*BytePool) GetSized

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

GetSized returns a byte slice with exactly the requested length.

func (*BytePool) Put

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

Put returns a byte slice to the pool for reuse. Slices larger than MaxPool are not pooled.

type StringMapPool

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

StringMapPool pools map[string]any for property maps.

func NewStringMapPool

func NewStringMapPool() *StringMapPool

NewStringMapPool creates a new string map pool.

func (*StringMapPool) Get

func (p *StringMapPool) Get() map[string]any

Get returns a cleared map from the pool.

func (*StringMapPool) Put

func (p *StringMapPool) Put(m map[string]any)

Put returns a map to the pool.

type Uint64Pool

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

Uint64Pool pools slices of uint64 for edge lists, ID collections, etc.

func NewUint64Pool

func NewUint64Pool() *Uint64Pool

NewUint64Pool creates a new uint64 slice pool.

func (*Uint64Pool) Get

func (p *Uint64Pool) Get(size int) []uint64

Get returns a uint64 slice with at least the requested capacity.

func (*Uint64Pool) Put

func (p *Uint64Pool) Put(s []uint64)

Put returns a uint64 slice to the pool.

Jump to

Keyboard shortcuts

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