Understand jschardet 4.0.0 performance characteristics
mainjschardet 4.0.0 is a TypeScript port of chardet 7 and offers significant improvements over version 3.1.4 in accuracy, throughput, and memory efficiency, though it has a higher initial 'cold start' cost.
Accuracy
- Overall Accuracy: ~99.2% (compared to 42.0% in v3).
- Language Detection: ~97.4% accuracy. Note that v3 does not support the
languagefield.
Throughput and Latency
- Steady State: Much faster than v3, processing approximately 6× more files per second.
- Tail Latency: Improved p95 latency compared to v3.
Cold Start (First Call Latency)
- Trade-off: The first call to
detect()is slower in v4 (~45ms) than in v3 (~0.5ms). This is because v4 uses zlib-compressed bigram models that are lazily decompressed during the firstdetect()call. Subsequent calls benefit from the faster steady-state throughput.
Memory Usage
- Efficiency: v4 is significantly more memory-efficient. It uses a dense bigram model format (one 64 KiB lookup table per language) that is loaded once and shared. This avoids the high per-call sparse-map allocations found in v3, resulting in a much lower peak Resident Set Size (RSS).