Skip to main content
For large corpora (100MB+), the default Python pipeline can be slow. Install DuckDB for automatic 3-15x faster frequency counting, and ensure Cython extensions are compiled for parallel segmentation.

Performance Optimization

DuckDB Acceleration

When DuckDB is installed, the pipeline automatically uses it for faster frequency counting:
Performance Comparison: How It Works:
  1. Arrow file is memory-mapped with PyArrow (efficient streaming)
  2. Arrow table is registered with DuckDB (zero-copy when possible)
  3. Single-pass SQL queries replace Python loops for aggregation
  4. Disk-based temp storage handles datasets larger than RAM
Requirements:
Resource Configuration: DuckDB automatically configures itself for optimal performance:
  • Uses all available CPU threads
  • Memory limit: adaptive, calculated as min(max(total_ram * 0.25, 2GB), 8GB), which scales with system RAM, clamped between 2GB and 8GB
  • Temp storage: Uses work directory (not /tmp)

Parallel Processing

Enable parallel processing for faster builds:

Optimal Worker Count

Batch Size Tuning

Larger batches improve throughput but use more memory:

Memory Optimization

Sharding for Large Files

The pipeline automatically shards input files for memory-efficient processing:

Intermediate Files

Use disk for intermediate Arrow files:

I/O Optimization

SSD Storage

Use SSD for both input and output:

Pre-sorted Input

Sorted input improves compression:

Sharding Large Corpora

Split large files for parallel ingestion:

Quality Optimization

Frequency Thresholds

Balance coverage vs. noise:

Database Size

Database Optimization

Index Strategy

Indexes are created automatically for fast lookups. The database includes:
  • idx_syllables_text - Syllable text lookups
  • idx_words_text - Word text lookups
  • idx_bigrams_w1_w2 - Bigram lookups
  • idx_trigrams_w1_w2_w3 - Trigram lookups

Vacuum

Database is automatically compacted after building:

Segmentation Optimization

Segmenter Selection

Choose segmenter based on needs:

Cython Acceleration

Ensure Cython extensions are compiled:

Benchmarking

Measure Build Time

Profile Memory

Troubleshooting

Out of Memory

Slow Build

Install DuckDB for significant speedup on all corpus sizes:
DuckDB is used by default when installed, providing 3-15x faster frequency counting via SQL-based aggregation.

Large Output Database

Small Corpus (<100MB)

Large Corpus (1-10GB)

Very Large Corpus (>10GB)

Recommended: Install DuckDB (pip install duckdb>=1.0.0) for optimal performance. The FrequencyBuilder automatically uses DuckDB when installed, providing 3-15x faster processing for large files.

See Also