Documentation
¶
Index ¶
- Constants
- func GetBuffer(size BufferSize) []byte
- func GetStringBuilder() *strings.Builder
- func PutBuffer(buffer []byte, size BufferSize)
- func PutStringBuilder(builder *strings.Builder)
- func TrackAllocation(bytes int64)
- func TrackBufferReuse()
- func TrackOperation(duration time.Duration)
- func TrackStringReuse()
- func WithBuffer(size BufferSize, fn func([]byte))
- func WithBufferReturn[T any](size BufferSize, fn func([]byte) T) T
- func WithStringBuilder(fn func(*strings.Builder) string) string
- type BufferPool
- type BufferPoolMetrics
- type BufferSize
- type MemoryTracker
- type PoolMetrics
- type StringBuilderPool
Constants ¶
const ( // Specialized buffer sizes HashBufferSize = 65536 // 64KB - optimized for hash operations TarBufferSize = 65536 // 64KB - optimized for tar operations // Maximum buffer size to retain in pool (prevents memory bloat) MaxRetainedBufferSize = 1048576 // 1MB )
const ( // StringBuilderSize is the default size for string operations StringBuilderSize = 1024 // For string operations (like AsFlags) DefaultBufferSize = 8192 // Default buffer size for I/O operations )
Variables ¶
This section is empty.
Functions ¶
func GetBuffer ¶
func GetBuffer(size BufferSize) []byte
GetBuffer gets a buffer from the default pool
func GetStringBuilder ¶
GetStringBuilder gets a string builder from the default pool
func PutBuffer ¶
func PutBuffer(buffer []byte, size BufferSize)
PutBuffer returns a buffer to the default pool
func PutStringBuilder ¶
PutStringBuilder returns a string builder to the default pool
func TrackAllocation ¶
func TrackAllocation(bytes int64)
TrackAllocation records an allocation using the default tracker
func TrackBufferReuse ¶
func TrackBufferReuse()
TrackBufferReuse increments buffer reuse counter using the default tracker
func TrackOperation ¶
TrackOperation records an operation duration using the default tracker
func TrackStringReuse ¶
func TrackStringReuse()
TrackStringReuse increments string reuse counter using the default tracker
func WithBuffer ¶
func WithBuffer(size BufferSize, fn func([]byte))
WithBuffer executes a function with a pooled buffer This ensures proper cleanup even if the function panics
func WithBufferReturn ¶
func WithBufferReturn[T any](size BufferSize, fn func([]byte) T) T
WithBufferReturn executes a function with a pooled buffer and returns a value This ensures proper cleanup even if the function panics
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool manages reusable byte slices for I/O operations
func NewBufferPool ¶
func NewBufferPool() *BufferPool
NewBufferPool creates a new BufferPool with optimized configurations
func (*BufferPool) Get ¶
func (p *BufferPool) Get(size BufferSize) []byte
Get retrieves a buffer from the appropriate pool
func (*BufferPool) GetMetrics ¶
func (p *BufferPool) GetMetrics() BufferPoolMetrics
GetMetrics returns pool efficiency metrics
func (*BufferPool) Put ¶
func (p *BufferPool) Put(buffer []byte, size BufferSize)
Put returns a buffer to the appropriate pool
type BufferPoolMetrics ¶
BufferPoolMetrics contains statistics about buffer pool usage
func GetBufferPoolMetrics ¶
func GetBufferPoolMetrics() BufferPoolMetrics
GetBufferPoolMetrics returns metrics for the default pool
func (BufferPoolMetrics) HitRate ¶
func (m BufferPoolMetrics) HitRate() float64
HitRate calculates the overall hit rate across all pools
type BufferSize ¶
type BufferSize int
BufferSize represents different buffer size categories
const ( HashBuffer BufferSize = iota TarBuffer // Alias for backward compatibility SmallBuffer = HashBuffer )
type MemoryTracker ¶
type MemoryTracker struct {
// contains filtered or unexported fields
}
MemoryTracker tracks basic memory usage metrics for pools
func NewMemoryTracker ¶
func NewMemoryTracker() *MemoryTracker
NewMemoryTracker creates a new memory tracker instance
func (*MemoryTracker) TrackAllocation ¶
func (mt *MemoryTracker) TrackAllocation(bytes int64)
TrackAllocation records an allocation event
func (*MemoryTracker) TrackBufferReuse ¶
func (mt *MemoryTracker) TrackBufferReuse()
TrackBufferReuse increments buffer reuse counter
func (*MemoryTracker) TrackOperation ¶
func (mt *MemoryTracker) TrackOperation(duration time.Duration)
TrackOperation records the duration of an operation
func (*MemoryTracker) TrackStringReuse ¶
func (mt *MemoryTracker) TrackStringReuse()
TrackStringReuse increments string reuse counter
type PoolMetrics ¶
PoolMetrics contains statistics about pool usage
func GetPoolMetrics ¶
func GetPoolMetrics() PoolMetrics
GetPoolMetrics returns metrics for the default pool
type StringBuilderPool ¶
type StringBuilderPool struct {
// contains filtered or unexported fields
}
StringBuilderPool manages reusable string.Builder instances
func NewStringBuilderPool ¶
func NewStringBuilderPool() *StringBuilderPool
NewStringBuilderPool creates a new StringBuilderPool
func (*StringBuilderPool) Get ¶
func (p *StringBuilderPool) Get() *strings.Builder
Get retrieves a string.Builder from the pool
func (*StringBuilderPool) GetMetrics ¶
func (p *StringBuilderPool) GetMetrics() PoolMetrics
GetMetrics returns pool efficiency metrics
func (*StringBuilderPool) Put ¶
func (p *StringBuilderPool) Put(builder *strings.Builder)
Put returns a string.Builder to the pool