A high-performance, multithreaded implementation of the popular ripgrep search tool, written in Rust. This project demonstrates a lightweight alternative to traditional text search utilities with concurrent processing capabilities.
- Multithreaded Architecture: Leverages multiple CPU cores for faster file searching
- SIMD Acceleration: Uses SIMD instructions for optimized pattern matching
- Memory Efficient: Implements buffered reading and overlap management to handle large files efficiently
- Real-time Output: Provides immediate search results as they are found
- Colored Output: Highlights matched patterns with syntax highlighting
The project is structured into four main components:
- DirWalker.rs: Manages directory traversal and file discovery using concurrent directory scanning
- SearchWorker.rs: Handles the core pattern matching logic using SIMD operations for performance
- PrintWorker.rs: Manages the output formatting and presentation of search results
- main.rs: Orchestrates the overall workflow with inter-thread communication
wide(v0.7): SIMD-accelerated operations for efficient pattern matchingnum_cpus(1.16): CPU detection for optimal thread count configuration
The implementation follows a producer-consumer pattern with three main threads:
- Directory Walker: Discovers files in the directory tree concurrently
- Search Workers: Multiple worker threads that scan files for the specified pattern
- Printer Thread: Formats and displays matches in real-time
The system dynamically adjusts the number of worker threads based on the number of available CPU cores (typically set to 2x the number of CPUs).
cargo run "search_pattern"The program will search for the specified pattern in all files within the current directory and its subdirectories. Results are displayed with:
- File name
- Line number
- Full line containing the match
- Highlighted pattern in red
- The implementation uses SIMD instructions to scan 32 bytes at a time
- Optimized buffering reduces I/O overhead
- Overlap buffers ensure patterns spanning buffer boundaries are detected
- Multithreaded design maximizes CPU utilization
# Clone the repository
git clone <repository-url>
# Build the project
cd grex
cargo build --release
# Run the executable
./target/release/grex "pattern"grex "pattern"This project is licensed under the MIT License - see the LICENSE file for details.