lpgauth

lpgauth

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

Showing Posts 1 to 5

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

manhvu

manhvu

Nice! I used jsonrs before, but I switched back to the OTP JSON library. I wish I had seen this earlier. Now I’m taking a different approach by replacing JSON with TOON.

lpgauth

lpgauth OP

Yes, you’re right. The default binaries assume the host CPU will support SSE2 or NEON. For better performance (AVX2 or AVX512) or if your CPU doesn’t support the base SSE2/NEON you can build from source by passing TORQUE_BUILD=true.

lpgauth

lpgauth OP

I didn’t know about jsonrs. I will add it to the benchmark suite!

lpgauth

lpgauth OP

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

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New

Other Trending Topics Top

akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews