High-performance Native C++ acceleration for Node.js File I/O and SIMD operations. This project is a Proof of Concept (PoC) demonstrating how much performance can be gained by moving critical workloads from JavaScript to native C++ addons.
TurboNodeIO benchmarks show significant improvements in file reading throughput, checksum calculations, and repeated I/O operations.
| Operation | Native C++ | Standard TS | Speedup |
|---|---|---|---|
| File Read (1GB) | 9.367 ms | 530.283 ms (sync) | 56x faster |
| File Read (100MB) | 0.179 ms | 56.796 ms (readFile) | 317x faster |
| File Read (10MB) | 0.132 ms | 4.465 ms (readFile) | 34x faster |
| File Read (100KB) | 0.070 ms | 0.314 ms (fd) | 4.5x faster |
| SIMD Checksum (1GB) | 50.086 ms | 2245.118 ms (JS) | 45x faster |
| SIMD Checksum (100MB) | 5.052 ms | 136.048 ms (JS) | 27x faster |
| SIMD Checksum (10MB) | 0.503 ms | 11.966 ms (MD5) | 24x faster |
| SIMD Checksum (100KB) | 0.003 ms | 0.200 ms (JS) | 71x faster |
| File Stats | 0.031 ms | 0.027 ms (sync) | Comparable |
Native C++ is 18.95x faster on average
Results measured on Windows hardware. Results vary depending on environment.
-
Node.js 16+
-
Python 3 (for node-gyp)
-
C++ toolchain:
- Windows: Visual Studio Build Tools 2019+
- macOS: Xcode Command Line Tools
- Linux: GCC/G++ 7+
npm install
npm run build:native
npm run benchmarknpm run benchmarkThe benchmark:
- Generates test files (100KB, 10MB, 100MB, 1GB)
- Compares 4 file-reading methods
- Compares 4 checksum algorithms
- Tests file stat operations
- Outputs detailed speed and throughput results
Sample output is available in the repository.
-
Memory-Mapped I/O (mmap)
- Zero-copy file access
- OS-level caching
- Minimal syscall overhead
-
SIMD (AVX2)
- Processes 256 bits per instruction
- Large-buffer checksum acceleration
-
Direct system calls
- Bypasses Node.js abstraction layers
- Lower overhead
If C++ addon build fails, TurboNodeIO uses optimized JavaScript implementations automatically.
.
├── file_io.cc
├── index.ts
├── benchmark.ts
├── binding.gyp
├── package.json
├── tsconfig.json
└── README.md
- Native addons are useful for CPU-bound or high-throughput workloads
- Performance benefits scale with larger inputs
- Overhead reduces gains on small files (<1MB)
- Development complexity trades for runtime speed
Modify benchmark.ts to:
- Change tested file sizes
- Increase iteration counts
- Add new read or hashing algorithms
- Benchmark real workloads
node-gyp rebuild --verboseicacls "m:\File_IO" /grant Users:F /tMIT
PRs and discussions are welcome.