Documentation
¶
Index ¶
- Variables
- type AllocatorStats
- type LanguageCommonTrigrams
- type SlabAllocator
- func (sa *SlabAllocator[T]) EstimateOptimalSize() int
- func (sa *SlabAllocator[T]) Get(capacity int) []T
- func (sa *SlabAllocator[T]) GetStats() AllocatorStats
- func (sa *SlabAllocator[T]) GetWithCapacity(existingLen, additionalCapacity int) []T
- func (sa *SlabAllocator[T]) GrowSlice(slice []T, additionalCapacity int) []T
- func (sa *SlabAllocator[T]) Put(slice []T)
- func (sa *SlabAllocator[T]) ResetStats()
- type SlabTierConfig
- type TrigramPredictor
- type TrigramStats
Constants ¶
This section is empty.
Variables ¶
var DefaultTierConfigs = []SlabTierConfig{
{Capacity: 8, Weight: 0.3},
{Capacity: 16, Weight: 0.3},
{Capacity: 32, Weight: 0.2},
{Capacity: 64, Weight: 0.1},
{Capacity: 128, Weight: 0.05},
{Capacity: 256, Weight: 0.03},
{Capacity: 512, Weight: 0.02},
}
DefaultTierConfigs provides sensible defaults for most workloads
var TrigramTierConfigs = []SlabTierConfig{
{Capacity: 8, Weight: 0.40},
{Capacity: 16, Weight: 0.40},
{Capacity: 32, Weight: 0.15},
{Capacity: 64, Weight: 0.03},
{Capacity: 128, Weight: 0.02},
}
TrigramTierConfigs is optimized for trigram location arrays based on distribution analysis
Functions ¶
This section is empty.
Types ¶
type AllocatorStats ¶
type AllocatorStats struct {
Allocations int64
Reuses int64
PoolHits int64
PoolMisses int64
TotalCapacity int64
}
AllocatorStats tracks allocation statistics
type LanguageCommonTrigrams ¶
type LanguageCommonTrigrams struct {
Language string
Patterns map[string]TrigramStats
}
LanguageCommonTrigrams contains language-specific common trigram patterns and their typical occurrence counts per file
type SlabAllocator ¶
type SlabAllocator[T any] struct { // contains filtered or unexported fields }
SlabAllocator is a generic, lock-free slab allocator for reducing memory allocation overhead. It uses pre-sized pools for different allocation sizes to minimize GC pressure.
func NewSlabAllocator ¶
func NewSlabAllocator[T any](configs []SlabTierConfig) *SlabAllocator[T]
NewSlabAllocator creates a new slab allocator with the given tier configurations
func NewSlabAllocatorWithDefaults ¶
func NewSlabAllocatorWithDefaults[T any]() *SlabAllocator[T]
NewSlabAllocatorWithDefaults creates a slab allocator with default tier configurations
func NewTrigramSlabAllocator ¶
func NewTrigramSlabAllocator[T any]() *SlabAllocator[T]
NewTrigramSlabAllocator creates a slab allocator optimized for trigram workloads
func (*SlabAllocator[T]) EstimateOptimalSize ¶
func (sa *SlabAllocator[T]) EstimateOptimalSize() int
EstimateOptimalSize estimates the best pool size for a given workload based on historical statistics
func (*SlabAllocator[T]) Get ¶
func (sa *SlabAllocator[T]) Get(capacity int) []T
Get returns a slice with at least the requested capacity. The returned slice has length 0 and capacity >= requested.
func (*SlabAllocator[T]) GetStats ¶
func (sa *SlabAllocator[T]) GetStats() AllocatorStats
GetStats returns current allocation statistics
func (*SlabAllocator[T]) GetWithCapacity ¶
func (sa *SlabAllocator[T]) GetWithCapacity(existingLen, additionalCapacity int) []T
GetWithCapacity returns a slice with exact capacity, growing if necessary This is useful when you need to append existing elements
func (*SlabAllocator[T]) GrowSlice ¶
func (sa *SlabAllocator[T]) GrowSlice(slice []T, additionalCapacity int) []T
GrowSlice grows a slice to accommodate additional elements, using slab allocation when possible
func (*SlabAllocator[T]) Put ¶
func (sa *SlabAllocator[T]) Put(slice []T)
Put returns a slice to the appropriate pool for reuse. Slices larger than the largest pool capacity are discarded.
func (*SlabAllocator[T]) ResetStats ¶
func (sa *SlabAllocator[T]) ResetStats()
ResetStats resets all statistics to zero
type SlabTierConfig ¶
type SlabTierConfig struct {
Capacity int
Weight float64 // Relative weight for this tier (for auto-sizing)
}
SlabTierConfig defines the configuration for a single slab tier
type TrigramPredictor ¶
type TrigramPredictor struct {
// contains filtered or unexported fields
}
TrigramPredictor provides intelligent pre-allocation estimates based on language patterns
func NewTrigramPredictor ¶
func NewTrigramPredictor(language string) *TrigramPredictor
NewTrigramPredictor creates a predictor for the specified language
func (*TrigramPredictor) GetCommonTrigrams ¶
func (tp *TrigramPredictor) GetCommonTrigrams(limit int) []TrigramStats
GetCommonTrigrams returns the most common trigrams for a language
func (*TrigramPredictor) PredictCapacity ¶
func (tp *TrigramPredictor) PredictCapacity(trigramString string, fileContent []byte) int
PredictCapacity estimates the appropriate capacity for a trigram based on: 1. Language-specific common patterns 2. File content analysis 3. Historical usage data
func (*TrigramPredictor) UpdateStats ¶
func (tp *TrigramPredictor) UpdateStats(trigramString string, actualCount int)
UpdateStats updates trigram statistics based on actual usage (learning)
type TrigramStats ¶
type TrigramStats struct {
Trigram string
AvgPerFile float64 // Average occurrences per file
MaxPerFile int // Maximum observed per file
Confidence float64 // How confident we are in this estimate (0-1)
Category string // "keyword", "operator", "common", "pattern"
}
TrigramStats tracks expected usage patterns for a trigram