Date: December 13, 2025
Environment: macOS (darwin 24.1.0), Node.js 24.1.0, ARM64
- TypeScript Parser: 335.59 ms avg (29,800 objects/sec)
- Native Parser: 340.66 ms avg (29,400 objects/sec)
- Speedup: 0.99x (TS parser is 1% faster)
- TypeScript Parser: 615.74 ms avg (81,200 objects/sec)
- Native Parser: 657.25 ms avg (76,200 objects/sec)
- Speedup: 0.94x (TS parser is 6% faster)
- TypeScript Parser: 981.33 ms avg (101,900 objects/sec)
- Native Parser: 1050.73 ms avg (95,200 objects/sec)
- Speedup: 0.93x (TS parser is 7% faster)
- TypeScript Parser: 5.48 ms avg (1,825,000 objects/sec)
- Native Parser: 10.71 ms avg (933,000 objects/sec)
- Speedup: 0.51x (TS parser is 2x faster)
Note: File-based parsing is significantly faster for both parsers due to OS-level caching.
-
TypeScript Parser:
- Total time: 30.10 ms
- Max lag: 0.15 ms
- Timer ticks: 2
-
Native Parser (yieldEvery=1024):
- Total time: 3,244.84 ms
- Max lag: 288.60 ms
- Timer ticks: 87
Key Finding: The TypeScript parser has significantly better latency characteristics, with minimal event loop blocking.
-
Thread Communication Overhead
- Native parser uses N-API Thread-Safe Functions (TSFN) to communicate between background thread and main thread
- Each batch requires a callback from native thread to JS thread
- This overhead dominates for small-to-medium workloads
-
JSON Parsing Strategy
- Native parser parses JSON in C++ then converts to JS objects
- TypeScript parser uses native
JSON.parse()which is highly optimized by V8 - V8's JSON.parse() is extremely fast and benefits from JIT compilation
-
Yielding Overhead
- The
yieldEverymechanism adds overhead withsetImmediate()calls - This can actually increase latency rather than decrease it for these workloads
- The
The native parser provides value in these scenarios:
-
Very Large Files
- For files >100MB, the background thread processing can prevent blocking
- Allows other work to continue on the main thread
-
File Descriptor Parsing
- Direct FD parsing without creating intermediate streams
- Useful for system-level integrations
-
True Background Processing
- When you need parsing to happen completely off the main thread
- Useful for worker-like scenarios
-
Memory Efficiency
- Can process files in chunks without loading entire file into memory
- Better for memory-constrained environments
Use the TypeScript parser (JSONParser class):
- Faster throughput
- Better latency characteristics
- Simpler API
- No native build required
- Better for streaming from processes/pipes
Use the Native parser (createJsonParserNativeFromFd):
- Very large files (>100MB)
- Direct file descriptor access
- When you need true background processing
- Memory-constrained environments
-
Native Parser Improvements:
- Reduce TSFN callback overhead (batch more aggressively)
- Consider using V8's JSON.parse() in native code instead of custom parser
- Optimize yieldEvery mechanism or make it optional
- Profile thread communication overhead
-
TypeScript Parser:
- Already well-optimized
- Consider adding streaming optimizations for very large streams
- Could benefit from SIMD optimizations for delimiter finding
-
General:
- Add performance regression tests to CI
- Document performance characteristics in README
- Consider adding performance benchmarks for different JSON sizes
- Node.js: v24.1.0
- Platform: macOS ARM64 (Apple Silicon)
- Test Data:
{"foo":N,"bar":"baz","nested":{"x":N}}per line - Iterations: 3-5 per test
- Warmup: 1 iteration before measurements
The TypeScript parser (JSONParser) is the better choice for most use cases, offering:
- 5-7% better throughput
- 2x better file-based performance
- Significantly better latency (0.15ms vs 288ms max lag)
- Simpler deployment (no native build required)
The native parser has value for specialized scenarios but needs optimization to compete with the highly-optimized V8 JSON.parse() used by the TypeScript implementation.