ass-core
High-performance ASS (Advanced SubStation Alpha) subtitle format parser and analyzer for Rust.
Features
- Zero-copy parsing: Efficient lifetime-generic AST with minimal allocations
- Full ASS v4+ support: Complete compatibility with libass and Aegisub
- Advanced analysis: Script linting, style resolution, and performance optimization
- SIMD acceleration: Optional SIMD-optimized parsing for maximum performance
- nostd compatible: Works in embedded and WASM environments
- Streaming support: Parse large files incrementally with bounded memory
Performance Targets
- Parse speed: <5ms for typical 1KB scripts
- Memory usage: <1.1x input size via zero-copy design
- Peak memory: <10MB for large subtitle files
- Incremental parsing: <5ms for typical edit operations (infrastructure ready)
Quick Start
Add to your Cargo.toml:
[]
= { = "0.1", = ["analysis"] }
Basic usage:
use Script;
let script_text = r#"
[Script Info]
Title: Example
ScriptType: v4.00+
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Hello World!
"#;
let script = parse?;
println!;
Advanced Usage
Script Analysis
use ScriptAnalysis;
let analysis = analyze?;
println!;
Linting
use ;
let config = default;
let issues = lint_script?;
for issue in issues
Streaming Parser
use StreamingParser;
let mut parser = new;
for chunk in file_chunks
let result = parser.finalize?;
Feature Flags
std(default): Standard library supportnostd: nostd compatibilityanalysis: Enable script analysis and lintingplugins: Extension registry supportsimd: SIMD-accelerated parsingarena: Arena allocation for improved performancestream: Streaming/chunked input supportserde: Serialization supportbenches: Enable benchmarking infrastructure
Architecture
The crate is organized into several modules:
parser: Core ASS parsing with zero-copy ASTanalysis: Deep script analysis and optimization detectionlinting: Comprehensive rule-based script validationutils: Common utilities and error types
Benchmarking
Performance benchmarks can be run with:
# Run all benchmarks
# Run specific benchmarks
The benchmarking suite includes:
- Parser benchmarks: Full parsing performance across complexity levels
- Incremental benchmarks: Infrastructure for validating incremental parsing
- Real-world scenarios: Testing against realistic subtitle patterns (anime, movies, karaoke, signs, educational content)
- Large-scale anime: Benchmarks for 30-50MB+ files with 10k-100k events (BD releases, complex OVAs)
- Editor simulation: Realistic editing patterns (typing, backspace, copy-paste)
- Memory benchmarks: Zero-copy efficiency and memory ratio validation
- Memory profiling: Simple tool to measure actual memory usage
Memory Profiling
To analyze memory usage without external tools:
# Run memory benchmarks
# Run simple memory profiler
The memory profiler shows:
- Input size vs actual memory usage
- Memory ratio (target: <1.1x)
- Parse time and section counts
- Pass/fail status for memory targets
Benchmark Configuration
For faster benchmark runs (e.g., in CI):
# Quick mode - fewer samples, shorter measurement time
QUICK_BENCH=1
# Run specific benchmark group
# Increase time limit for complex benchmarks
If you see warnings about unable to complete samples:
- This is normal for complex benchmarks
- The results are still valid
- Use
QUICK_BENCH=1for faster iteration - Or increase measurement time as suggested
Compatibility
- ASS v4.00+: Full support including advanced features
- SSA v4: Legacy compatibility mode
- libass extensions: Support for renderer-specific features
- Aegisub compatibility: Full support for Aegisub-specific features
License
Licensed under the MIT license.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.