Making the rav1d Video Decoder 1% Faster

https://news.ycombinator.com/rss Hits: 8
Summary

*on macOS with an M3 chip*slightly more than 1%, on a specific benchmark, without any new unsafe codeA while ago, memorysafety.org announced a contest for improving performance of rav1d, a Rust port of the dav1d AV1 decoder.As this literally has my name written on it, I thought it would be fun to give it a try (even though I probably can’t participate in the contest).This is a write-up about two small performance improvements I found (1st PR, 2nd PR) and how I found them (you can also jump to the summary in the end).Background and Approachrav1d is a port of dav1d, created by (1) running c2rust on dav1d, (2) incorporating dav1d’s asm-optimized functions, and (3) changing the code to be more Rust-y and safer.The authors also published a detailed article about the process and the performance work they did.More recently, the contest was announced, with the baseline being:Our Rust-based rav1d decoder is currently about 5% slower than the C-based dav1d decoder.Video decoders are notoriously complex pieces of software, but because we are comparing the performance of two similar deterministic binaries we might be able to avoid a lot of that complexity - with the right tooling.We can’t expect to find huge wins, and some regressions might be too-hard-to-tackle (for example, LLVM finding a Rust function harder to optimize than the C version), but it’s worth a shot, especially since aarch64 (my environment) is probably less optimized than x86_64.My approach here was to:Use a sampling profiler to capture snapshots of both runs on the same input.Use the optimized asm calls as “anchors” since they should match perfectly.Compare the Rust and C versions function by function, and if there’s a big enough discrepancy, dive into that function.BaselineFirst things first, we need to build and compare perf locally (using hyperfine and the sample files noted in the contest’s rules and rav1d’s CI).We’ll be using the single threaded version (--threads 1) to keep things simple.For rav1d:$ git ...

First seen: 2025-05-22 12:24

Last seen: 2025-05-22 19:26