Documentation
¶
Overview ¶
ABOUTME: This file implements sync.Pool for reusing expensive objects like goquery documents and HTTP response bodies. It reduces garbage collection pressure and improves performance in high-throughput parsing scenarios.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( GlobalDocumentPool = NewDocumentPool() GlobalResponseBodyPool = NewResponseBodyPool() GlobalBufferPool = NewBufferPool() GlobalStringBuilderPool = NewStringBuilderPool() )
Global pool instances for efficient object reuse
Functions ¶
func WithPooledBuffer ¶
WithPooledBuffer executes a function with a pooled buffer and automatically returns it to the pool when done
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool manages a pool of bytes.Buffer objects for efficient string building
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() *bytes.Buffer
Get retrieves a bytes.Buffer from the pool
func (*BufferPool) Put ¶
func (bp *BufferPool) Put(buf *bytes.Buffer)
Put returns a bytes.Buffer to the pool
type DocumentPool ¶
type DocumentPool struct {
// contains filtered or unexported fields
}
DocumentPool manages a pool of goquery.Document objects for reuse
func NewDocumentPool ¶
func NewDocumentPool() *DocumentPool
NewDocumentPool creates a new DocumentPool with proper initialization
func (*DocumentPool) Put ¶
func (dp *DocumentPool) Put(doc *goquery.Document)
Put returns a goquery.Document to the pool for reuse
type PoolStats ¶
type PoolStats struct {
DocumentsInUse int
BuffersInUse int
StringBuildersInUse int
ResponseBuffersInUse int
}
PoolStats provides statistics about pool usage for monitoring
func GetPoolStats ¶
func GetPoolStats() PoolStats
GetPoolStats returns current pool usage statistics Note: sync.Pool doesn't provide built-in stats, so this is an approximation
type PooledStringBuilder ¶
type PooledStringBuilder struct {
// contains filtered or unexported fields
}
PooledStringBuilder provides a convenient way to use pooled string builders
func NewPooledStringBuilder ¶
func NewPooledStringBuilder() *PooledStringBuilder
NewPooledStringBuilder creates a new PooledStringBuilder
func (*PooledStringBuilder) Close ¶
func (psb *PooledStringBuilder) Close()
Close returns the builder to the pool
func (*PooledStringBuilder) Reset ¶
func (psb *PooledStringBuilder) Reset()
Reset resets the builder for reuse
func (*PooledStringBuilder) String ¶
func (psb *PooledStringBuilder) String() string
String returns the built string
func (*PooledStringBuilder) WriteString ¶
func (psb *PooledStringBuilder) WriteString(s string) (int, error)
WriteString writes a string to the pooled builder
type ResponseBodyPool ¶
type ResponseBodyPool struct {
// contains filtered or unexported fields
}
ResponseBodyPool manages a pool of response body readers for reuse
func NewResponseBodyPool ¶
func NewResponseBodyPool() *ResponseBodyPool
NewResponseBodyPool creates a new ResponseBodyPool
func (*ResponseBodyPool) Get ¶
func (rbp *ResponseBodyPool) Get() *bytes.Buffer
Get retrieves a buffer from the pool for reading response bodies
func (*ResponseBodyPool) Put ¶
func (rbp *ResponseBodyPool) Put(buf *bytes.Buffer)
Put returns a buffer to the pool after reading a response body
func (*ResponseBodyPool) ReadResponseBody ¶
func (rbp *ResponseBodyPool) ReadResponseBody(resp *http.Response) ([]byte, error)
ReadResponseBody efficiently reads an HTTP response body using pooled buffers
type StringBuilderPool ¶
type StringBuilderPool struct {
// contains filtered or unexported fields
}
StringBuilderPool manages a pool of strings.Builder objects for efficient string concatenation
func NewStringBuilderPool ¶
func NewStringBuilderPool() *StringBuilderPool
NewStringBuilderPool creates a new StringBuilderPool
func (*StringBuilderPool) Get ¶
func (sbp *StringBuilderPool) Get() *strings.Builder
Get retrieves a strings.Builder from the pool
func (*StringBuilderPool) Put ¶
func (sbp *StringBuilderPool) Put(sb *strings.Builder)
Put returns a strings.Builder to the pool