async-rev-buf
A high-performance async buffered reader for reading lines in reverse order from files and streams.
Overview
async-rev-buf provides RevBufReader, an async buffered reader that reads lines from the end of a file or stream
backwards to the beginning. This is particularly useful for processing log files, JSON Lines data, or any line-oriented
data where you need the most recent entries first.
Features
- High Performance: 8+ million lines/sec reverse reading throughput
- Async/Await Support: Full compatibility with tokio's async ecosystem
- Streaming Interface: Clean
lines().next_line().awaitpattern following tokio conventions - Memory Efficient: Fixed buffer size with minimal allocations
- Unicode Support: Proper handling of UTF-8 text and various line endings
- Dual API: Both streaming interface and direct method access
- Type Safety: Purpose-built API prevents forward/reverse reading confusion
Quick Start
Streaming Interface (Recommended)
use RevBufReader;
use File;
async
Direct Method Access
use RevBufReader;
use File;
async
Performance
Latest Benchmark Results
Comprehensive performance comparison against all available async and sync reverse readers:
| Lines | RevBufReader | rev_buf_reader (sync, memory intensive) | tokio-rev-lines | Performance |
|---|---|---|---|---|
| 100 | 9.1M lines/sec | 12.8M lines/sec | 3.8M lines/sec | 2.4x faster |
| 1,000 | 8.5M lines/sec | 12.8M lines/sec | 3.5M lines/sec | 2.4x faster |
| 5,000 | 8.4M lines/sec | 13.1M lines/sec | 3.3M lines/sec | 2.5x faster |
Performance Analysis
🏆 Outstanding Async Performance:
- 8-9 million lines/sec consistently across all test sizes
- 71% of sync performance while maintaining full async capabilities
- 2.4-2.5x faster than existing async alternatives (tokio-rev-lines)
- Scales well with larger files
🎯 When to Choose Our RevBufReader:
- Building async/await applications
- Need concurrent file processing
- Integrating with tokio ecosystem
- Want non-blocking I/O
- Processing multiple files simultaneously
- Need the fastest async reverse reader available
📊 Competitive Analysis:
- vs tokio-rev-lines: 2.4-2.5x performance improvement
- vs sync libraries: 71% performance while staying async
- Memory Efficient: Fixed 8KB buffer (configurable)
- Best-in-class: Leading async reverse reading performance
Run Benchmarks
API Design Philosophy
Purpose-Built for Reverse Reading:
Instead of forcing compatibility with AsyncBufRead (which would cause 50-70% performance loss), we provide a clean,
purpose-built API optimized specifically for reverse reading.
Benefits of Current Design:
- 🚀 Maximum Performance: No compatibility overhead
- 🎯 Clear Semantics: Obviously designed for reverse reading
- 🔒 Type Safety: Prevents accidental forward/reverse confusion
- 📖 Better UX: Clear documentation and intent
Limitations
Technical Constraints:
- Requires
AsyncSeek- works with files but not all streams - Designed for text files with reasonable line lengths
- Line detection based on
\nand\r\nboundaries - Not compatible with
AsyncBufReadtrait (by design for performance)
Performance Context:
- Optimized for async: 8+ million lines/sec is excellent for async reverse reading
- Use case matters: Perfect for log tailing, recent data access, concurrent processing
Contributing
Contributions welcome! Please feel free to submit issues, feature requests, or pull requests.
Focus Areas:
- Performance optimizations
- Additional async stream types support
- Documentation improvements
- Real-world usage examples
Part of the async-jsonl ecosystem for efficient async JSON Lines processing.