| Implementation | Time | Speedup vs TS | Status |
|---|---|---|---|
| native-optimized | 16.42 ms | 1.07x faster ✅ | WINNER |
| ts | 17.59 ms | 1.00x (baseline) | - |
| worker | 30.53 ms | 0.58x | Needs more optimization |
| native | 31.12 ms | 0.56x | Needs more optimization |
The native-optimized implementation (using passRawBuffers: true) is now 7% faster than the TS parser!
- Zero-copy buffer transfer - External buffers avoid string copying
- V8's optimized JSON.parse() - Uses JIT-compiled parser
- Background I/O - File reading happens in C++ thread
- Efficient batching - Larger batches (1024) reduce overhead
- ✅ Bulk property creation using
napi_define_properties - ✅ Optimized array creation
- ✅ Larger I/O buffers (128KB)
- ✅ Better string handling
- ✅ Zero-copy external buffers
- ✅ Direct JSON.parse() on main thread
- ✅ Larger batch sizes (1024)
- ✅ Optimized buffer parsing loop
- ✅ Larger batch sizes (512)
- ✅ Optimized array operations
- ✅ Better memory management
- Try MessagePack or binary format instead of structured cloning
- Optimize postMessage batching
- Reduce structured cloning overhead
- Further optimize object creation
- Maybe use V8 internal APIs if possible
- Pre-allocate object shapes
Native-optimized is now faster than TS! 🎉
The key was using zero-copy buffers + V8's optimized JSON.parse() instead of C++ parsing + object construction.