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
- func GetBytes(size int) []byte
- func GetBytesSized(size int) []byte
- func GetStringMap() map[string]any
- func GetUint64s(size int) []uint64
- func PutBytes(b []byte)
- func PutStringMap(m map[string]any)
- func PutUint64s(s []uint64)
- type BufferBuilder
- func (b *BufferBuilder) Bytes() []byte
- func (b *BufferBuilder) Len() int
- func (b *BufferBuilder) Release()
- func (b *BufferBuilder) Reset()
- func (b *BufferBuilder) Write(p []byte)
- func (b *BufferBuilder) WriteByte(c byte) error
- func (b *BufferBuilder) WriteString(s string)
- func (b *BufferBuilder) WriteUint32BE(v uint32)
- func (b *BufferBuilder) WriteUint64BE(v uint64)
- type BytePool
- type StringMapPool
- type Uint64Pool
Constants ¶
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 GetBytesSized ¶
GetBytesSized returns a byte slice with exact length from the default pool.
func GetStringMap ¶
GetStringMap returns a string map from the default pool.
func GetUint64s ¶
GetUint64s returns a uint64 slice from the default pool.
func PutStringMap ¶
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) 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 ¶
Get returns a byte slice with at least the requested capacity. The returned slice has length 0 and the specified capacity.
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.