Documentation
¶
Overview ¶
Package streaming provides memory-efficient processing for large inputs (>500K tokens).
Index ¶
- Constants
- func EstimateTokens(content string) int
- func ProcessLargeContent(content string, processor ChunkProcessor) (string, error)
- func ShouldStream(content string) bool
- type ArenaAllocator
- type BackpressureController
- type Chunk
- type ChunkProcessor
- type FilterProcessor
- type MemoryMappedFile
- type Pipeline
- type Result
- type Stats
- type StreamingMetrics
- type StreamingProcessor
- func (sp *StreamingProcessor) Process(input string, processor func(string) string) string
- func (sp *StreamingProcessor) ProcessWithMetrics(input string, processor func(string) string) (string, *StreamingMetrics)
- func (sp *StreamingProcessor) SetAdaptive(adaptive bool)
- func (sp *StreamingProcessor) SetChunkSize(size int)
- func (sp *StreamingProcessor) SetThreshold(threshold int)
- func (sp *StreamingProcessor) ShouldStream(input string) bool
- type StreamingWriter
- type ZeroCopyReader
Constants ¶
const ( // DefaultChunkSize is the default size for streaming chunks (~4K tokens). DefaultChunkSize = 16 * 1024 // 16KB // MaxMemoryBuffer is the maximum memory buffer size. MaxMemoryBuffer = 100 * 1024 * 1024 // 100MB )
Variables ¶
This section is empty.
Functions ¶
func EstimateTokens ¶
EstimateTokens estimates the token count for content.
func ProcessLargeContent ¶
func ProcessLargeContent(content string, processor ChunkProcessor) (string, error)
ProcessLargeContent processes large content in chunks.
func ShouldStream ¶
ShouldStream determines if content should use streaming.
Types ¶
type ArenaAllocator ¶
type ArenaAllocator struct {
// contains filtered or unexported fields
}
ArenaAllocator provides arena-based memory allocation.
func (*ArenaAllocator) Alloc ¶
func (a *ArenaAllocator) Alloc(size int) []byte
Alloc allocates memory from the arena.
type BackpressureController ¶
type BackpressureController struct {
// contains filtered or unexported fields
}
func NewBackpressureController ¶
func NewBackpressureController(maxPending int) *BackpressureController
func (*BackpressureController) IsBlocked ¶
func (b *BackpressureController) IsBlocked() bool
func (*BackpressureController) Release ¶
func (b *BackpressureController) Release()
func (*BackpressureController) TryAcquire ¶
func (b *BackpressureController) TryAcquire() bool
type ChunkProcessor ¶
ChunkProcessor processes individual chunks.
type FilterProcessor ¶
type FilterProcessor struct {
// contains filtered or unexported fields
}
FilterProcessor adapts filter.Engine to ChunkProcessor.
func (*FilterProcessor) Name ¶
func (p *FilterProcessor) Name() string
Name implements ChunkProcessor.
type MemoryMappedFile ¶
type MemoryMappedFile struct {
// contains filtered or unexported fields
}
MemoryMappedFile provides memory-mapped file access.
func MapFile ¶
func MapFile(path string) (*MemoryMappedFile, error)
MapFile maps a file into memory.
func (*MemoryMappedFile) Data ¶
func (m *MemoryMappedFile) Data() []byte
Data returns the mapped data.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline processes content in streaming fashion.
func NewPipeline ¶
func NewPipeline(processor ChunkProcessor) *Pipeline
NewPipeline creates a new streaming pipeline.
func (*Pipeline) ProcessReader ¶
ProcessReader processes content from a reader.
func (*Pipeline) SetChunkSize ¶
SetChunkSize sets the chunk size.
func (*Pipeline) SetMaxMemory ¶
SetMaxMemory sets the maximum memory.
func (*Pipeline) SetWorkerCount ¶
SetWorkerCount sets the number of workers.
type StreamingMetrics ¶
type StreamingProcessor ¶
type StreamingProcessor struct {
// contains filtered or unexported fields
}
func NewStreamingProcessor ¶
func NewStreamingProcessor() *StreamingProcessor
func (*StreamingProcessor) Process ¶
func (sp *StreamingProcessor) Process(input string, processor func(string) string) string
func (*StreamingProcessor) ProcessWithMetrics ¶
func (sp *StreamingProcessor) ProcessWithMetrics(input string, processor func(string) string) (string, *StreamingMetrics)
func (*StreamingProcessor) SetAdaptive ¶
func (sp *StreamingProcessor) SetAdaptive(adaptive bool)
func (*StreamingProcessor) SetChunkSize ¶
func (sp *StreamingProcessor) SetChunkSize(size int)
func (*StreamingProcessor) SetThreshold ¶
func (sp *StreamingProcessor) SetThreshold(threshold int)
func (*StreamingProcessor) ShouldStream ¶
func (sp *StreamingProcessor) ShouldStream(input string) bool
type StreamingWriter ¶
type StreamingWriter struct {
// contains filtered or unexported fields
}
StreamingWriter writes large output efficiently.
func NewStreamingWriter ¶
func NewStreamingWriter(w io.Writer, bufferSize int) *StreamingWriter
NewStreamingWriter creates a streaming writer.
func (*StreamingWriter) Write ¶
func (s *StreamingWriter) Write(p []byte) (n int, err error)
Write implements io.Writer.
func (*StreamingWriter) Written ¶
func (s *StreamingWriter) Written() int64
Written returns total bytes written.
type ZeroCopyReader ¶
type ZeroCopyReader struct {
// contains filtered or unexported fields
}
ZeroCopyReader provides zero-copy reading.
func NewZeroCopyReader ¶
func NewZeroCopyReader(data []byte) *ZeroCopyReader
NewZeroCopyReader creates a zero-copy reader.
func (*ZeroCopyReader) Read ¶
func (z *ZeroCopyReader) Read(p []byte) (n int, err error)
Read implements io.Reader.