optimization

package
v1.0.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package optimization provides performance optimization utilities

Index

Constants

This section is empty.

Variables

View Source
var ErrPoolClosed = &poolError{"pool is closed"}

ErrPoolClosed is returned when operating on a closed pool.

Functions

This section is empty.

Types

type BufferPool

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

BufferPool provides a pool of reusable byte buffers.

func NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool creates a new buffer pool.

func (*BufferPool) Get

func (p *BufferPool) Get() *bytes.Buffer

Get retrieves a buffer from the pool.

func (*BufferPool) Put

func (p *BufferPool) Put(buf *bytes.Buffer)

Put returns a buffer to the pool.

type ByteSlicePool

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

ByteSlicePool provides a pool of reusable byte slices.

func NewByteSlicePool

func NewByteSlicePool() *ByteSlicePool

NewByteSlicePool creates a new byte slice pool.

func (*ByteSlicePool) Get

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

Get retrieves a byte slice of the specified size.

func (*ByteSlicePool) Put

func (p *ByteSlicePool) Put(buf []byte)

Put returns a byte slice to the pool.

type ConnectionPool

type ConnectionPool[T any] struct {
	// contains filtered or unexported fields
}

ConnectionPool manages a pool of reusable connections.

func NewConnectionPool

func NewConnectionPool[T any](
	maxSize int,
	factory func() (T, error),
	reset func(T) error,
	closeFunc func(T) error,
) *ConnectionPool[T]

NewConnectionPool creates a new connection pool.

func (*ConnectionPool[T]) Close

func (p *ConnectionPool[T]) Close() error

Close closes all connections in the pool.

func (*ConnectionPool[T]) Get

func (p *ConnectionPool[T]) Get() (T, error)

Get retrieves a connection from the pool.

func (*ConnectionPool[T]) Put

func (p *ConnectionPool[T]) Put(conn T) error

Put returns a connection to the pool.

func (*ConnectionPool[T]) Size

func (p *ConnectionPool[T]) Size() int

Size returns the current number of connections in the pool.

type ObjectPool

type ObjectPool[T any] struct {
	// contains filtered or unexported fields
}

ObjectPool provides a generic object pool.

func NewObjectPool

func NewObjectPool[T any](newFunc func() T) *ObjectPool[T]

NewObjectPool creates a new object pool.

func (*ObjectPool[T]) Get

func (p *ObjectPool[T]) Get() T

Get retrieves an object from the pool.

func (*ObjectPool[T]) Put

func (p *ObjectPool[T]) Put(obj T)

Put returns an object to the pool.

Jump to

Keyboard shortcuts

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