Lightning-fast string searching with AVX2 and multi-threading optimization. Achieves up to 9 GB/s search speeds on Google CloudShell!
| Test Case | Speed | Notes |
|---|---|---|
| Full Scan (not found) | 23.2 GB/s | Optimal case with early rejection |
| Typical Search | 5.5 GB/s | Real-world pattern matching |
| Early Find | 2.2 GB/s | Quick termination |
| Single Thread | 4.6 GB/s | Still highly optimized |
╔══════════════════════════════════╗
║ FLASHSEARCH TEST ║
╚══════════════════════════════════╝
Configuration:
Dataset: 10M JSON records (0.69GB)
Threads: 1-16 optimized scaling
CPU: CloudShell VM (2.2GHz)
Storage: NVMe SSD
Best Results:
• Search Speed: 5.5 GB/s
• Full Scan: 9.0 GB/s
• "Not Found": 23.2 GB/s
• Optimal Threads: 4-8
- AVX2 SIMD Optimized: Processes 32 bytes per instruction
- Multi-threaded: Scales efficiently across CPU cores
- Zero-overlap Search: No redundant scanning between threads
- Profile-Guided Optimization: Auto-tunes for your hardware
- Memory Mapped Files: Efficient large file handling
- Early Termination: Stops immediately when pattern found
# Clone repository
git clone https://github.com/dwip-the-dev/FlashSearch.git
cd FlashSearch
# Build with standard optimizations
make
# Build with extreme optimizations
make extreme
# Build for profiling (PGO)
make profile
./flashsearch_profile # Run 3-4 times
make profile-opt# Build and run benchmark
make run
# Or run challenge mode
make challenge
make run-challenge| Command | Description |
|---|---|
make |
Standard optimized build |
make extreme |
Maximum optimizations (AVX2, BMI, etc.) |
make debug |
Debug build with sanitizers |
make profile |
Profile-guided optimization build |
make clean |
Clean all build artifacts |
- Memory Mapping: Files are
mmap()'d for zero-copy access - AVX2 SIMD: Uses 256-bit registers to compare 32 bytes at once
- Thread Pool: Divides work without overlap between threads
- Early Stopping: All threads stop immediately when pattern found
- Cache Optimization: CPU cache-aware memory access patterns
- Each thread gets non-overlapping chunks
- Sub-divides into 16 sub-chunks for work stealing
- CPU affinity pinning for better cache locality
- Atomic operations for coordination
FlashSearch/
├── benchmark.c # Performance test suite
├── challenge.c # Ultimate challenge mode
├── flashsearch.c # Core search algorithm
├── flashsearch.h # Header file with API
├── Makefile # Build system
└── README.md # This file
#include "flashsearch.h"
// Basic search
Context ctx;
const char *result = flashsearch_hyper(
data, data_len,
pattern, pattern_len,
thread_count, &ctx
);
// Get performance metrics
double speed_gbps = flashsearch_gbps(&ctx, elapsed_ms);- Use 4-8 threads (optimal for most systems)
- Longer patterns reduce false positives
- Run multiple times to warm CPU caches
- Ensure dataset fits in available memory
- Use PGO for hardware-specific tuning
// Processes 128 bytes per iteration (4x AVX2 vectors)
__m256i v1 = _mm256_loadu_si256((const __m256i*)data);
__m256i c1 = _mm256_cmpeq_epi8(v1, pattern_vec);
int mask = _mm256_movemask_epi8(c1);- 64-byte cache line aligned reads
- Hardware prefetching hints
- Non-temporal access patterns for large scans
- Early Find:
"key":"key00000123"(first 0.001%) - Middle Find:
"id":5000000 - Late Find:
"id":9999999(last record) - Multiple Matches:
"tag":"tag1234" - Not Found:
"nonexistent":"xyz123"(full scan)
- Fork the repository
- Create a feature branch
- Submit a pull request
- Include benchmarks showing improvement
MIT License - see LICENSE file for details.
- Google CloudShell for testing infrastructure
- GCC compiler team for excellent optimizations
- Intel for AVX2 instruction set
Made with ❤️ by dwip-the-dev
Star this repo if you found it useful!