Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 1.85 KB

File metadata and controls

61 lines (43 loc) · 1.85 KB

Final Performance Results

Current Status (After Optimizations)

Quick Benchmark: 5,000 nested JSON objects

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

✅ SUCCESS: Native-Optimized Beats TS!

The native-optimized implementation (using passRawBuffers: true) is now 7% faster than the TS parser!

Why Native-Optimized Wins:

  1. Zero-copy buffer transfer - External buffers avoid string copying
  2. V8's optimized JSON.parse() - Uses JIT-compiled parser
  3. Background I/O - File reading happens in C++ thread
  4. Efficient batching - Larger batches (1024) reduce overhead

Optimizations Applied

Native Parser:

  • ✅ Bulk property creation using napi_define_properties
  • ✅ Optimized array creation
  • ✅ Larger I/O buffers (128KB)
  • ✅ Better string handling

Native-Optimized (Buffers):

  • ✅ Zero-copy external buffers
  • ✅ Direct JSON.parse() on main thread
  • ✅ Larger batch sizes (1024)
  • ✅ Optimized buffer parsing loop

Worker:

  • ✅ Larger batch sizes (512)
  • ✅ Optimized array operations
  • ✅ Better memory management

Next Steps to Beat TS Completely

For Worker:

  • Try MessagePack or binary format instead of structured cloning
  • Optimize postMessage batching
  • Reduce structured cloning overhead

For Native (non-buffer):

  • Further optimize object creation
  • Maybe use V8 internal APIs if possible
  • Pre-allocate object shapes

Conclusion

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.