Skip to content

Latest commit

 

History

History
49 lines (34 loc) · 1.74 KB

File metadata and controls

49 lines (34 loc) · 1.74 KB

Final Performance Results

Current Status

Quick Benchmark: 5,000 nested JSON objects

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

Key Findings

✅ Native-Optimized is Very Close!

  • 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

Why Native-Optimized Can't Beat TS (When Idle)

  1. Buffer allocation overhead - External buffers still have allocation cost
  2. Buffer → String conversion - buf.toString('utf8') has overhead
  3. JSON.parse() on main thread - Same as TS, but with buffer overhead
  4. TSFN callback overhead - Thread communication has cost

Why It's Still Valuable

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!

Optimizations Applied

  1. ✅ Bulk property creation (napi_define_properties)
  2. ✅ Zero-copy external buffers
  3. ✅ Larger batch sizes (2048)
  4. ✅ Optimized array operations
  5. ✅ Better memory management

Conclusion

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!