Documentation
¶
Overview ¶
Package pool provides reusable byte buffer pools to reduce GC pressure.
Index ¶
- func GetBuffer() *[]byte
- func GetBytesReader(b []byte) *bytes.Reader
- func GetSizedBuffer(hint int64) *[]byte
- func GetTimer(d time.Duration) *time.Timer
- func PutBuffer(b *[]byte)
- func PutBytesReader(r *bytes.Reader)
- func PutSizedBuffer(b *[]byte)
- func PutTimer(t *time.Timer)
- func PutTracer(col *TimingCollector)
- type TimingCollector
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
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
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
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
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
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.