Parallel Matching
For large texts, use parallel matching to leverage multiple goroutines.
Overview
Parallel matching splits text into chunks and processes them concurrently, significantly improving performance for large inputs.
Basic Usage
matches, err := ac.FindParallel(largeText, &acor.ParallelOptions{
Workers: 4,
Boundary: acor.ChunkBoundaryWord,
})
if err != nil {
panic(err)
}
Chunk Boundaries
Chunk boundaries ensure matches aren’t split across chunks:
ChunkBoundaryWord (default)
Splits at word boundaries, ideal for natural language text:
opts := &acor.ParallelOptions{
Workers: 4,
Boundary: acor.ChunkBoundaryWord,
}
ChunkBoundaryLine
Splits at line breaks, ideal for log files:
opts := &acor.ParallelOptions{
Workers: 4,
Boundary: acor.ChunkBoundaryLine,
}
ChunkBoundarySentence
Splits at sentence endings, ideal for document processing:
opts := &acor.ParallelOptions{
Workers: 4,
Boundary: acor.ChunkBoundarySentence,
}
Performance Tuning
Worker Count
Choose worker count based on CPU cores:
workers := runtime.NumCPU()
For I/O-bound workloads, consider higher counts:
workers := runtime.NumCPU() * 2
Chunk Size
Control chunk size with the ChunkSize option:
opts := &acor.ParallelOptions{
Workers: 4,
ChunkSize: 10000, // 10KB chunks
}
When to Use Parallel Matching
- Text size > 100KB
- Many pattern matches expected
- CPU cores available for parallel work
When to Avoid
- Small texts (< 10KB)
- Single-match scenarios
- Resource-constrained environments
Next Steps
- Batch Operations - Optimize bulk keyword operations
- API Reference - Complete API documentation