pool

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pool provides the two-tier sync.Pool used by every Fluent render call. Buffers below Threshold are recycled through the small pool; larger buffers go through the large pool, and anything above MaxPoolSize is discarded so the pool cannot retain pathological allocations.

Pooling is on by default and can be toggled at runtime with Enable and Disable. Configure sizing through SetThreshold and SetMaxPoolSize, and observe what the pool is doing by attaching a JSONL writer with SetDiagnostics. Most callers reach the pool indirectly through github.com/jpl-au/fluent.NewBuffer rather than importing this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disable

func Disable()

Disable turns off sync.Pool optimisations. Subsequent Get calls return fresh buffers and Put becomes a no-op until Enable is called.

func DiscardOversized

func DiscardOversized() bool

DiscardOversized reports whether buffers larger than MaxPoolSize are discarded when returned to the pool.

func Enable

func Enable()

Enable turns on sync.Pool optimisations. Pooling is enabled by default; call this only after a prior Disable.

func Enabled

func Enabled() bool

Enabled reports whether pool optimisations are currently enabled.

func Get

func Get(hint int) *bytes.Buffer

Get retrieves a buffer from the pool, sized according to the hint. If pooling is disabled, it returns a new buffer.

func MaxPoolSize

func MaxPoolSize() int

MaxPoolSize returns the maximum buffer size in bytes that the pool will retain.

func Put

func Put(buf *bytes.Buffer)

Put returns a buffer to the pool. If pooling is disabled or the buffer is too large, it is discarded.

func SetDiagnostics added in v0.2.0

func SetDiagnostics(w io.Writer)

SetDiagnostics enables pool diagnostics. When w is non-nil, every Get and Put writes a JSONL entry to w. Pass nil to disable. Safe to call at any time - typically called once at application startup.

func SetMaxPoolSize

func SetMaxPoolSize(size int, drop bool)

SetMaxPoolSize configures the maximum buffer size in bytes to keep in pools. Buffers larger than size are discarded when drop is true; when drop is false they are still discarded today (the rebound path is not implemented).

func SetThreshold added in v0.1.1

func SetThreshold(size int)

SetThreshold sets the size threshold in bytes between the small and large pools. Buffers with capacity below the threshold are recycled through the small pool; the rest go through the large pool.

func Threshold added in v0.1.1

func Threshold() int

Threshold returns the size threshold in bytes between the small and large pools.

Types

This section is empty.

Jump to

Keyboard shortcuts

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