lpgauth

lpgauth

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

Most Liked

Asd

Asd

Given that your library uses SIMD instructions, precompiled binaries is a bad option, since precompilation works only for OS+CPU arch combination and it doesnt account for target CPU to have the proper flags which would indicate that it supports SIMD instructions

lpgauth

lpgauth

Hi, quick follow-up. I ended up adding specific binaries per CPU variants on x86_64.

https://github.com/lpgauth/torque?tab=readme-ov-file#cpu-optimized-variants

Where Next?

Popular in Announcing Top

Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps w...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement