| Implementation | Time | vs TS | Notes |
|---|---|---|---|
| ts | ~18 ms | 1.00x (baseline) | Fastest when idle |
| native-optimized | ~22 ms | 0.82x | Very close! |
| worker | ~32 ms | 0.57x | Structured cloning overhead |
| native | ~134 ms | 0.14x | C++ parsing overhead |
- Only 22% slower than TS (was 50%+ slower before)
- Uses zero-copy buffers + V8's JSON.parse()
- Background I/O in C++ thread
- Best choice when main thread is busy
- Buffer allocation overhead - External buffers still have allocation cost
- Buffer → String conversion -
buf.toString('utf8')has overhead - JSON.parse() on main thread - Same as TS, but with buffer overhead
- TSFN callback overhead - Thread communication has cost
Under 50% CPU load:
- Native-optimized: I/O in background, parsing on main
- TS: Everything on main thread (blocks)
- Native-optimized should win under load!
- ✅ Bulk property creation (
napi_define_properties) - ✅ Zero-copy external buffers
- ✅ Larger batch sizes (2048)
- ✅ Optimized array operations
- ✅ Better memory management
Native-optimized is now only 22% slower than TS when idle, and should be faster under load when the main thread is busy.
The fundamental limitation: When the main thread is idle, doing everything directly (TS parser) has zero overhead, which is hard to beat. But when the main thread is busy, native-optimized's background I/O + efficient parsing wins!