PERFORMANCE

DAWG Performance Analysis

Executive Summary

The DAWG (Directed Acyclic Word Graph) implementation provides exceptional performance for dictionary operations with automatic encoding management. Key highlights:

  • Sub-microsecond lookups for ASCII text (0.1μs per lookup)

  • Automatic compression for Unicode text (up to 89 unique characters)

  • 38% memory reduction through minimization

  • Seamless encoding transitions without data loss

Performance Metrics

Operation Speeds

OperationDatasetTimePer-Operation
Insert (ASCII)10,000 words0.005s0.5μs
Insert (Unicode)1,000 words0.213s213μs
Insert (Mixed)5,000 words0.363s73μs
Lookup (ASCII)10,000 lookups0.001s0.1μs
Lookup (Unicode)1,000 lookups0.100s100μs
Contains Check10,000 checks0.0005s0.05μs
Prefix Search100 searches0.002s18μs
Minimization5,000 words0.010s-

Memory Usage

  • ASCII Dictionary: ~6 bytes per word (after minimization)

  • Unicode Dictionary: ~4 nodes per word (compressed mode)

  • Node Reduction: 30-40% through minimization

  • Fixed-width encoding: Enables memory-mapped file support

Automatic Encoding Management

The DAWG automatically transitions between three encoding modes:

  1. ASCII Mode (default)

    • 7-bit encoding for pure ASCII text

    • Fastest performance

    • Minimal memory usage

  2. Compressed Unicode Mode

    • Activated when Unicode detected

    • Maps up to 89 unique character grapheme clusters to 7-bit space

  3. UTF-32 Mode

    • Full Unicode support

    • Used when >89 unique characters

    • Fixed-width for memory mapping

Benchmarking Details

Test Environment

  • Platform: macOS (Darwin 24.4.0)

  • Test data: 52-word English dictionary + 1,000 Cyrillic words

  • Implementation: Pure Raku with automatic optimization

Key Findings

  1. Compression Overhead: Only 6% performance penalty for automatic compression detection

  2. Rebuild Performance:

    • UTF-32 rebuild: 64ms

    • Compressed rebuild: 93ms

  3. Minimization Impact: 38% node reduction with 10ms processing time

  4. Memory Efficiency: Compressed mode uses same memory as ASCII for up to 89 characters

Use Case Recommendations

Ideal For:

  • Spell checkers: Sub-microsecond word validation

  • Autocomplete: Fast prefix matching (18μs)

  • Dictionary compression: 30-40% space savings

  • Multi-language apps: Automatic Unicode handling

  • Large vocabularies: Consistent performance at scale

Performance Tips:

  1. Minimize after bulk insertions for 30-40% memory savings

  2. Use contains() for existence checks (fastest operation)

  3. Let automatic compression handle encoding decisions

  4. Pre-sort words for slightly faster insertion

Technical Advantages

  1. Zero-configuration Unicode support - Automatic detection and compression

  2. Memory-mapped file compatibility - Fixed-width encoding modes

  3. Cache-friendly - Minimized node structure improves locality

  4. Predictable performance - O(k) operations where k = word length

  5. Graceful degradation - Automatic upgrade to wider encodings as needed

Conclusion

The DAWG implementation offers production-ready performance with intelligent encoding management. The automatic compression feature provides optimal space/time tradeoffs without manual configuration, making it suitable for both simple ASCII dictionaries and complex multilingual applications.

DAWG v0.1.6

Directed Acyclic Word Graph implementation for efficient string storage and retrieval

Authors

  • Danslav Slavenskoj

License

Artistic-2.0

Dependencies

JSON::FastNativeCall

Test Dependencies

Provides

  • DAWG
  • DAWG::Binary
  • DAWG::Builder
  • DAWG::MMap
  • DAWG::Node
  • DAWG::Search::Fuzzy
  • DAWG::Search::Pattern
  • DAWG::Serializer

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.