SIMD-Accelerated Generation Strategy

=============================================================================

Strategic plan for SIMD (Single Instruction, Multiple Data) optimizations

in the Rust native engine to achieve 20-30% additional performance for

massive datasets (100M+ records).

Status: Strategic Planning Phase

Target: Rust native engine (ext/fake_data_dsl_native/)

=============================================================================

Overview

SIMD instructions allow processing multiple data elements in parallel using specialized CPU instructions. For FakeDataDSL, SIMD can accelerate:

  1. UUID Generation - Generate 4 UUIDs per SIMD operation (AVX-512)
  2. Number Formatting - Parallel integer-to-string conversion
  3. JSON Serialization - Vectorized string escaping and formatting
  4. String Operations - Parallel character manipulation

Target Hot Paths

1. UUID Generation (Highest Impact)

Current: Sequential UUID generation using uuid crate SIMD Opportunity: Generate 4-8 UUIDs per operation using AVX-512

// Pseudo-code for SIMD UUID generation
#[target_feature(enable = "avx512f")]
unsafe fn generate_uuid_batch_simd(count: usize) -> Vec<Uuid> {
    // Generate 4 UUIDs per SIMD operation
    // Use AVX-512 for 512-bit operations
}

Expected Speedup: 3-4x for UUID-heavy schemas

2. Number Formatting

Current: Sequential integer-to-string conversion SIMD Opportunity: Format multiple integers in parallel

// Use SIMD for parallel number formatting
// Process 8-16 integers per operation

Expected Speedup: 2-3x for number-heavy schemas

3. JSON Serialization

Current: Sequential character-by-character escaping SIMD Opportunity: Vectorized string escaping

// Use SIMD to escape multiple characters in parallel
// Detect special characters (", \, \n, etc.) in batches

Expected Speedup: 1.5-2x for JSON output

Implementation Strategy

Phase 1: UUID SIMD (Highest ROI)

  1. Research: Evaluate simd-uuid crate or implement custom AVX-512 UUID generation
  2. Benchmark: Measure current UUID generation throughput
  3. Implement: Add SIMD UUID generation path
  4. Validate: Ensure deterministic output with seeds
  5. Deploy: Feature flag for SIMD UUID generation

Phase 2: Number Formatting SIMD

  1. Research: Evaluate itoa SIMD optimizations or custom implementation
  2. Implement: Parallel integer formatting
  3. Benchmark: Compare against current implementation

Phase 3: JSON Serialization SIMD

  1. Research: Evaluate simd-json or custom SIMD escaping
  2. Implement: Vectorized string escaping
  3. Benchmark: Measure JSON serialization throughput

Technical Considerations

CPU Feature Detection

// Runtime CPU feature detection
if is_x86_feature_detected!("avx512f") {
    use_simd_path()
} else if is_x86_feature_detected!("avx2") {
    use_avx2_path()
} else {
    use_scalar_path()
}

Fallback Strategy

  • Always provide scalar fallback for CPUs without SIMD support
  • Use runtime feature detection, not compile-time
  • Gracefully degrade on older CPUs

Determinism

  • SIMD operations must maintain deterministic output with seeds
  • Ensure same seed produces same output regardless of SIMD path
  • Test determinism across different CPU architectures

Performance Targets

Operation Current SIMD Target Speedup
UUID generation ~500K/sec ~2M/sec 4x
Number formatting ~1M/sec ~2.5M/sec 2.5x
JSON serialization ~300K/sec ~500K/sec 1.7x
Overall (mixed) ~3.5M/sec ~4.5M/sec 1.3x

Implementation Timeline

  • Q1: Research and prototype UUID SIMD
  • Q2: Implement and benchmark UUID SIMD
  • Q3: Add number formatting SIMD
  • Q4: Add JSON serialization SIMD

Risks & Mitigation

  1. CPU Compatibility: Not all CPUs support AVX-512

    • Mitigation: Runtime detection with fallback
  2. Complexity: SIMD code is harder to maintain

    • Mitigation: Extensive tests, clear documentation
  3. Determinism: SIMD operations must be deterministic

    • Mitigation: Careful seed handling, comprehensive tests

Success Metrics

  • 20-30% overall performance improvement for 100M+ record generation
  • No regression on CPUs without SIMD support
  • Maintain 100% deterministic output with seeds
  • Zero increase in memory usage

References