We created a safer AV1 decoder, rav1d, by forking the dav1d decoder and rewriting the C code in Rust. It works well except our Rust is 5% slower than the C. We're not sure why so we're offering a $20k bounty to figure it out and make the Rust code faster. https://www.memorysafety.org/blog/rav1d-perf-bounty/
$20,000 rav1d AV1 Decoder Performance Bounty

In March of 2023 we announced that we were starting work on a safer high performance AV1 decoder called rav1d, written in Rust. We partnered with Immunant to do the engineering work. By September of 2024 rav1d was basically complete and we learned a lot during the process. Today rav1d works well—it passes all the same tests as the dav1d decoder it is based on, which is written in C. It’s possible to build and run Chromium with it.

Prossimo
@joshaas isn’t this something Thomas Dullien’s profiler tool can identify?
@dtl I'm not a Rust person, but it's definitely worth a look. Maybe I can speed up the C version for a different prize.
@fast_code_r_us @dtl slow down the C code by 5% and get the 20k?
@joshaas it's a little unfortunate that the contest isn't open to people in Norway or Switzerland...
@streganil EEA and Switzerland added. Happy hacking!
@joshaas ... I cannot believe that worked. thanks!
@joshaas if I find a bug in the C Version and the fix slows it down to the Rust Version does that count?
@joshaas @mcc Can I get the bounty if I can make the C code run slower?

@beej
>> After racking our brains for options, we decided to offer a bounty pool of $20,000 for getting rav1d to performance parity with dav1d.

Ignoring the actual rules which are also posted, looks like you can make it slower but not too slow.
@joshaas @mcc

@efraim @joshaas @mcc Oof, I’m out, then. I’m so bad at coding, I’d probably end up making it unusable. 😛

@joshaas

As I enjoy optimizing things, I thought I give it a try. But opened a link and it is geographically restricted. I'm not based in one of those mentioned areas. So it's a bye bye...

@joshaas

Well, the memory safety will incur some overhead.

Sadly my brain no longer works well enough to compare assembly side by side and debug the compilers.

@joshaas a 5% difference seems like the kind of thing that may run up against some of basic underlying assumptions made by hyperfine—see bestguess by @jamiejennings particularly the "About measurement quality" section for an elaboration on this topic
Jamie A. Jennings / bestguess · GitLab

GitLab.com

GitLab
@joshaas this seems like a reason to hire or contract with a seasoned rust compiler engineer instead of an open bounty call ending in december. i assume it's worth much more than $20k to you but that negotiating an appropriate contract with an expert would allow them to charge much more
@joshaas ok your optimization post https://www.memorysafety.org/blog/rav1d-performance-optimization/ says there was a 3% perf reduction across LLVM versions and you're asking someone from the internet to get 5% for $20k? from the rest of that post this seems like incredibly nontrivial compiler engineering work that's really more of an LLVM problem to solve. i'm also very surprised that you started by using c2rust instead of engineering it from scratch and am concerned that the large scale changes in code design which may be necessary would not be easily accepted into the repo—if you don't have headcount to fix this yourself, do you have enough to review it?
Optimizing rav1d, an AV1 Decoder in Rust

AV1 is an increasingly important video format and it needs a memory safe, high performance decoder. We worked with the team at Immunant to develop rav1d. Performance is critical in this context, so we've asked Stephen Crane, CTO of Immunant, to explain their efforts in achieving performance parity. If you'd like to dig deeper, check out our recent blog post about how we ported the C AV1 decoder to Rust.

Prossimo
@joshaas the post mentions hyperfine specifically but it's not clear if that's how dav1d benchmarks itself—are you using the same harness they are? the bestguess tool is still research software but dr. jennings does note some flaws in the way tools like hyperfine currently work which are worth considering if your performance differential is at 5%
@joshaas i assume having a safe and fast av1 decoder is worth an incredibly large sum of money to google since chrome was mentioned as the use case so i would really recommend escalating this to one of their many talented LLVM contributors or offering contract work to an LLVM engineer to help figure this out
@joshaas i might finally recommend taking a look at the c2rust tool and considering whether it can be used with a setting that avoids things like bounds checking by default, to let you get a lower bound for runtime and then remove needless unsafety rather than the other way around. having to remove tons of bounds checking was mentioned multiple times in the optimization post and since we know or suspect that dav1d is safe (has it been fuzzed?) it might be easier to start closer to its own code. just some thoughts
@joshaas in fact the longer i think about it the more i think it's absurd that a translator tool was used to produce c code from rust code for such an incredibly performance-critical implementation, instead of having an expert who deeply understands the codec architect the rust version from scratch. isn't the entire point of rust that it's not a literal translation of c idioms?
@joshaas i know there is a massive DARPA grant called TRACTOR for translating c to rust with LLMs—is this work related to that at all? because it seems to share the philosophy that rust is just a magically safer c which doesn't require real thoughtful design work to achieve safety + performance
@joshaas i'm particularly upset that the optimization post mentioned this work shepherding the output of c2rust was supported by @sovtechfund—automatic translation of expert-designed C code so that massive corporations like google can avoid paying for anyone to develop enough of their own AV1 expertise to architect an idiomatic rust version which furthers their browser monopoly does not seem like fostering "sovereignty" to me. it seems like "austerity"