Field notes/Mediarusty_jpxrusty_jbig2

A JPEG 2000 decoder in Rust, timed against OpenJPEG: rusty_jpx and rusty_jbig2

How two new remade_ffmpeg_rs crates were made faster in a day: callgrind counts, pinned-core timing, null pairs, and every output digest held identical to the first release.

Signed by Tim Almond·
Painted bookbinder in a plain stone barn doorway at dawn holding a single cream sheet up to the low sun, a stack of blank folios on a trestle beside him and a few warm light motes drifting in the beam
How fast is the rusty_jpx JPEG 2000 decoder compared with OpenJPEG?

In the 0.1.1 tuning pull request, single-core rusty_jpx decodes took 59 to 84 percent of the time OpenJPEG 2.5.4 needed on six test images, winning 12 of 12 timing pairs each. That OpenJPEG build had SSE2 paths only, and null pairs on the same box ranged from 0.91 to 1.36.

I maintain remade_ffmpeg_rs at Remade with Rust, the crate catalog that comes out of MATA. On Wednesday, 25 November 2026, two new crates landed in that workspace: rusty_jpx, a JPEG 2000 decoder, and rusty_jbig2, a decoder for the black-and-white JBIG2 scan format. Both exist because PDFs embed those formats as image filters, and no house crate could read them. Version 0.1.0 of each went to crates.io between 12:40 and 12:55 PM MST. By 2:30 PM the tuning was on main, and release pull request 217 bumps each crate to 0.1.1.

This page is about that tuning: how the speed claims were measured, what they say, and what they leave open. The conformance story for the first release sits in the pull requests, and I only summarize it here. Everything below comes from public pull requests in the Remade-With-Rust organization. Nothing was re-run for this article.

Correct first, then a JPEG 2000 decoder worth timing

Speed work on a codec means nothing unless the output stays right, so the order mattered. Pull request 222 made rusty_jpx correct and compared full sample buffers against OpenJPEG 2.5.4. Of 304 streams generated with opj_compress across random options, 244 were exact, 42 were within one level, and 18 differed for reasons the request lists one by one. Its first timing table, one pinned core and 12 alternating process pairs, put the two decoders level, and the author wrote it plainly: "Read it as level, not faster."

The JBIG2 side, pull request 220, matched the reference images on 269 of 269 streams from two public suites before anyone looked at speed. The tuning requests followed the first publish, and each one checked its output digests against the 0.1.0 release it was about to replace.

How the tuning was measured

The two tuning requests, 225 for rusty_jpx and 226 for rusty_jbig2, use the same two instruments, and they disagree in an instructive way.

Counting instructions, not only seconds

The main instrument is callgrind, which counts the instructions a decode executes. It is close to deterministic: on the same binary, a null run differed by 0 to 190 instructions. That lets a small change show up even on a shared box. For rusty_jpx the count fell 31.0 to 54.1 percent across eight images with AVX2 on, and 30.0 to 36.3 percent on the SSE2-only build. For rusty_jbig2 the committed test streams fell from 1,333 million instructions to 661 million, a 50.4 percent cut.

Wall clock, paired and with a null arm

Counts are not time, so each request also timed decodes on one pinned core, alternating old and new builds in pairs. The jpx wall-clock gain was smaller than the count drop: 15 to 27 percent faster, winning 12 of 12 pairs on every image, against null pairs of 0.98 to 1.03. The author believes the gap is branch misprediction in the MQ arithmetic decoder, but did not measure it.

What changed in the code

Most of the jpx win is in kernels. The wavelet, dequantize, colour transform and level-shift steps each got AVX2, SSE2, NEON and scalar versions from one source, with no fused multiply-add, so the 9/7 wavelet gives the same bits on every instruction set. JBIG2 took a different route: no intrinsics at all, wider words for drawing and context building, and fewer copies of the page. Each crate now keeps its only unsafe code in one private module, and the READMEs were corrected to say so.

What the OpenJPEG comparison does and does not show

The headline figure is the one people will quote, so it deserves the most care.

The numbers as published

After tuning, request 225 reports the ratio of minimum decode times, rusty_jpx over OpenJPEG 2.5.4, winning 12 of 12 pairs on each image: 0.74 for a 9/7 image, 0.61 tiled, 0.84 for 5/3 lossless, 0.83 with bypass, 0.82 for a large 4:2:0 photo and 0.59 for a 2K frame. Lower means rusty_jpx took less time.

The caveats that travel with them

The OpenJPEG build used has SSE2 paths only, while rusty_jpx picked AVX2 at run time. The box was shared, and OpenJPEG timed against itself ranged from 0.91 to 1.36. NEON has correctness evidence under qemu, but no timing. It is one thread on six images, not a corpus. The crate is also single-threaded today, so a multi-threaded JPEG 2000 decoder could still beat it on a large page, and no such comparison has been run. Earlier rusty_tiff work used the same discipline, and the resource-limits note explains why both new crates bound their work before allocating.

Where to go from here

Neither crate is wired into the rff command line yet, and neither has an encoder. If you parse PDFs in Rust and need a JPEG 2000 decoder with no C underneath, try them from docs.rs and report a file that decodes differently. The conversion pins are on the rusty_jpx repo page and the rusty_jbig2 repo page. The same release pull request bumps rusty_svgtree to a breaking 0.2.0 with SVG filters and text. For context on the wider rebuild, see the pure-Rust alternative to FFmpeg and the FFai page.

FAQ

Quick answers for builders evaluating this technology.

Why count instructions with callgrind instead of only timing decodes?

Instruction counts barely move between runs, so a small change shows up even on a busy machine. The pull requests report a null run of the counter differing by 0 to 190 instructions. Wall-clock timing is then used to confirm that fewer instructions became less time, which it did only partly.

Did the speed work change any decoded output?

No. For rusty_jpx, digests of every component of 659 files, decoded three ways for 1,977 results, matched 0.1.0 on both the AVX2 and SSE2-only builds. For rusty_jbig2, output digests were equal before and after on every case, and cargo semver-checks found no API change.

Which CPUs get the vector kernels?

rusty_jpx has AVX2, SSE2, NEON and scalar versions of its wavelet, dequantize, colour and level-shift kernels, chooses AVX2 at run time, and avoids fused multiply-add so results match bit for bit. NEON was checked for correctness under qemu but not timed. rusty_jbig2 uses no intrinsics at all.

How does rusty_jbig2 compare with the hayro-jbig2 crate?

In its first pull request, rusty_jbig2 executed 212, 191 and 105 million instructions on three 300 dpi streams where hayro-jbig2 0.4.0 needed 264, 228 and 143 million. Unpinned wall-clock runs put it 1.08 to 1.56 times faster, which the author labels indicative only. That was before the later tuning.

What else shipped in the same remade_ffmpeg_rs release?

Release pull request 217, merged on 25 November 2026, also bumps rusty_svgtree to 0.2.0, a breaking version that adds SVG filters and text, and rusty_aac to 2.2.0. It moves most rff crates from 0.9.0 to 0.9.1 and the rff command line to 0.4.17.