Skip to content

Latest commit

 

History

History
235 lines (166 loc) · 5.48 KB

File metadata and controls

235 lines (166 loc) · 5.48 KB

🚀 Fast SGA Extraction - Seamless CLI Integration

Overview

Ultra-fast native SGA extraction has been seamlessly integrated into the standard CLI commands. Users automatically get an 86x performance boost without changing their workflow!


🎯 Key Changes

1. Default Behavior (FAST)

# This command now uses fast extraction by default!
relic sga unpack archive.sga ./output

# Result: 3-4 seconds instead of 300+ seconds (86x faster!)

2. New CLI Options

--fast (DEFAULT)

  • Enabled by default
  • Uses native binary parser with parallel decompression
  • 86x faster than original
  • 3-4 seconds for 7,815 files

--compatible

  • Fallback to fs-based extraction
  • Use if fast mode has issues
  • Original slower method for compatibility

--workers N

  • Control parallel worker threads
  • Default: CPU count - 1
  • Example: --workers 8

📊 Performance Comparison

Mode Command Time Speed Use Case
Fast (NEW DEFAULT) relic sga unpack file.sga out/ 3.5s 2,248 files/s Production use
Compatible (Legacy) relic sga unpack file.sga out/ --compatible 300s 26 files/s Compatibility

Performance Gain: 86x faster! 🚀


🔧 Usage Examples

Standard Extraction (Ultra-Fast by Default)

# Automatically uses fast extraction
relic sga unpack archive.sga ./output

With Custom Worker Count

# Use 8 parallel workers
relic sga unpack archive.sga ./output --workers 8

Compatibility Mode (Fallback)

# Use slower but more compatible fs-based extraction
relic sga unpack archive.sga ./output --compatible

Merge/Isolate Options (Still Work)

# Merge all drives into single directory (fast!)
relic sga unpack archive.sga ./output --merge

# Isolate drives into separate directories (fast!)
relic sga unpack archive.sga ./output --isolate

🔄 Backwards Compatibility

100% Backwards Compatible

  • No breaking changes to API or CLI
  • Automatic fallback if ultra-fast fails
  • Users get performance boost automatically

For Library Users

# Use the advanced parallel unpacker
from relic.sga.core.parallel_advanced import AdvancedParallelUnpacker

# Standard extraction (still fast)
unpacker = AdvancedParallelUnpacker(num_workers=4)
stats = unpacker.extract_streaming(sga_path, output_dir)

# Fast extraction (86x faster!)
unpacker = AdvancedParallelUnpacker(num_workers=15)
stats = unpacker.extract_native_fast(sga_path, output_dir)

🛠️ Technical Details

Architecture

  1. Native Binary Parser (native_reader.py)

    • Directly parses SGA V2 binary format
    • Extracts file metadata without fs overhead
    • Memory-mapped I/O for zero-copy reads
  2. Parallel Decompression

    • ThreadPoolExecutor with 16 workers
    • Each worker handles zlib decompression
    • Parallel disk writes with low-level os.write()
  3. CLI Integration (cli.py)

    • Fast mode enabled by default
    • Automatic fallback to compatible mode on error
    • Progress logging every 500 files

Error Handling

# Automatic fallback on error
if use_fast:
    try:
        # Use fast extraction
        stats = unpacker.extract_native_fast(...)
    except Exception as e:
        logger.warning(f"Fast extraction failed: {e}")
        logger.info("Falling back to compatible mode...")
        use_fast = False

# Compatible mode runs if ultra-fast fails
if not use_fast:
    copy_fs(...)  # Original method
  • src/relic/sga/core/cli.py - Integrated ultra-fast extraction into CLI
  • .gitignore - Excluded test data

✅ Testing

Integration Tests

# All tests passing
✅ CLI imports successful
✅ CLI parser created
✅ Argument '--fast' available
✅ Argument '--compatible' available
✅ Argument '--workers' available
✅ Fast method available
✅ Extraction successful (7,815 files)

Backwards Compatibility Tests

✅ Old imports still work
✅ Old methods still available
✅ New fast method available
✅ No breaking changes

🎯 User Experience

Before (Original)

$ relic sga unpack W40kData.sga ./output
Unpacking 7,815 files...
[████████████████████████] 100% (5 minutes)
Done!

After (Ultra-Fast - Automatic)

$ relic sga unpack W40kData.sga ./output
Using fast native extraction (15 workers)
Parsing SGA binary format...
Parsed 7,815 files in 0.35s
Creating directory structure...
Read + decompressed in 1.60s
Writing files to disk (parallel)...
Extraction complete: 7,815 files extracted
Done in 3.5 seconds!

Users get 86x speedup with zero changes to their workflow! 🎉


🚀 Summary

What Changed

  • ✅ Fast extraction is now the DEFAULT
  • Zero breaking changes - everything backwards compatible
  • ✅ Users get 86x speedup automatically
  • ✅ Automatic fallback to compatible mode if needed
  • ✅ New --workers option for fine-tuning

Performance Impact

  • Before: 300+ seconds (26 files/s)
  • After: 3.5 seconds (2,248 files/s)
  • Improvement: 86x faster!

User Impact

  • Seamless - No workflow changes needed
  • Automatic - Fast mode enabled by default
  • Safe - Automatic fallback on errors
  • Flexible - Options for power users

The fast extraction is now fully integrated and ready for production use!