Torque - SIMD-accelerated JSON encoding and decoding

Torque is a high-performance JSON library for Elixir built on sonic-rs via Rustler NIFs. It targets workloads where JSON throughput is a bottleneck — think bidstream processing, high-volume API ingestion, or any hot path that spends meaningful time in encode/decode.

Why Torque?

Raw throughput on a 1.2 KB OpenRTB payload (Apple M2 Pro, OTP 28, Elixir 1.19):

Decode

Library ips mean median p95 p99 memory
torque 255.8K 3.91 µs 3.58 µs 4.54 µs 9.21 µs 1.56 KB
simdjsone 185.9K 5.38 µs 5.00 µs 6.38 µs 12.67 µs 1.59 KB
jiffy 152.4K 6.56 µs 5.83 µs 8.58 µs 15.75 µs 1.56 KB
otp json 130.9K 7.64 µs 7.17 µs 9.33 µs 16.50 µs 7.73 KB
jason 109.1K 9.17 µs 8.54 µs 11.04 µs 18.13 µs 9.54 KB

Encode

Library ips mean median p95 p99 memory
torque encode (proplist) 869.6K 1.15 µs 1.04 µs 1.29 µs 1.42 µs 88 B
torque iodata (proplist) 854.7K 1.17 µs 1.08 µs 1.33 µs 1.46 µs 64 B
torque iodata (map) 775.2K 1.29 µs 1.17 µs 1.46 µs 1.63 µs 64 B
torque encode (map) 800.0K 1.25 µs 1.17 µs 1.25 µs 1.50 µs 88 B
otp json (iodata) 735.3K 1.36 µs 0.83 µs 1.25 µs 13.54 µs 3928 B
jiffy 537.6K 1.86 µs 1.63 µs 2.00 µs 2.29 µs 120 B
otp json (binary) 448.4K 2.23 µs 1.58 µs 2.63 µs 15.00 µs 3992 B
jason 284.9K 3.51 µs 2.42 µs 14.63 µs 16.63 µs 3912 B

Features

  • SIMD-accelerated decoding (AVX2/SSE2 on x86_64, NEON on ARM)

  • Ultra-low memory encoder — 64 B per encode vs ~4 KB for OTP json / Jason

  • parse/1 + get/2 / get_many/2 for selective field extraction (JSON Pointer / RFC 6901)

  • Batch field extraction via a single NIF call

  • Automatic dirty CPU scheduler dispatch for large inputs

  • jiffy-compatible {proplist} encoding for easy migration

Installation

elixir

def deps do
  [{:torque, "~> 0.1.1"}]
end

Precompiled binaries are available for common targets. To build from source, install a stable Rust toolchain and set TORQUE_BUILD=true.

Hex: https://hex.pm/packages/torque

https://github.com/lpgauth/torque

5 Likes