pool

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package pool provides reusable byte buffer pools to reduce GC pressure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuffer

func GetBuffer() *[]byte

GetBuffer returns a pooled byte slice of at least mediumBufferSize (backward compat). Deprecated: Use GetSizedBuffer for better performance.

func GetBytesReader added in v0.1.2

func GetBytesReader(b []byte) *bytes.Reader

GetBytesReader returns a pooled bytes.Reader initialised with the given bytes. The reader must be returned via PutBytesReader when done.

func GetSizedBuffer added in v0.1.2

func GetSizedBuffer(hint int64) *[]byte

GetSizedBuffer returns a pooled byte slice sized appropriately for the given hint. hint should be the Content-Length (or estimated size) of the response body. The slice must be returned via PutSizedBuffer when done.

func GetTimer added in v0.1.2

func GetTimer(d time.Duration) *time.Timer

GetTimer returns a pooled *time.Timer configured for the given duration. The timer is reset to d and ready for use. Must be returned via PutTimer when done.

func PutBuffer

func PutBuffer(b *[]byte)

PutBuffer returns a buffer to the pool (assumes mediumBufferSize). Deprecated: Use PutSizedBuffer for better performance.

func PutBytesReader added in v0.1.2

func PutBytesReader(r *bytes.Reader)

PutBytesReader returns a bytes.Reader to the pool. Must be called after the reader is no longer needed to allow reuse. Do not use the reader after calling this function.

func PutSizedBuffer added in v0.1.2

func PutSizedBuffer(b *[]byte)

PutSizedBuffer returns a buffer to the correct pool based on its capacity. Do not use the slice after calling this function.

func PutTimer added in v0.1.2

func PutTimer(t *time.Timer)

PutTimer returns a timer to the pool. Must be called when done with the timer to allow reuse. Ensures timer is stopped and the channel is drained.

func PutTracer added in v0.1.2

func PutTracer(col *TimingCollector)

PutTracer returns a tracer entry to the pool. Must be called after timing is finalised to reset for reuse.

Types

type TimingCollector added in v0.1.2

type TimingCollector struct {
	DNSStart     time.Time
	DNSDone      time.Time
	ConnStart    time.Time
	ConnDone     time.Time
	TLSStart     time.Time
	TLSDone      time.Time
	FirstByte    time.Time
	RequestStart time.Time
	// contains filtered or unexported fields
}

TimingCollector accumulates timing checkpoints during an HTTP request.

func GetTracer added in v0.1.2

func GetTracer() (*TimingCollector, *httptrace.ClientTrace)

GetTracer returns a pooled TimingCollector and ClientTrace. The collector is populated as the request progresses. Must be returned via PutTracer when done.

func (*TimingCollector) Reset added in v0.1.2

func (tc *TimingCollector) Reset()

Reset clears all timing values for reuse.

Jump to

Keyboard shortcuts

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