$20,000 If You Can Make This Rust Program As Fast As C
Written by Harry Fairhead   
Monday, 19 May 2025

This is a storm in a Rust bucket. Prosimo decided that a good test of Rust was to convert the existing dav1d decoder from C to Rust. Everything seems to have gone well, but the Rust version is still 5% or so slower than the C version. There is $20,000 waiting for you if you can speed it up.

So Rust isn't quite the equal of C and the FFmpeg project, very C-oriented, dived in with what looks like sarcasm:

ffmpeg

And as a C afficionado I can see the temptation to knock the mighty Rust but...

Before you get enthusiastic about going in search of that elusive 5% or before you write off Rust as being hopelessly inefficient you need to know the fine detail.

The idea was to create a Rust version of dav1d that was memory-safe as a drop-in replacement for the C version. The project consised of 50k lines of C and 250k lines of assembly. Wow, that is a lot of assembler! So much assembler that you could ask if this is really a C project at all. The conversion to Rust made use of the unmodified assembler and all of the data structures were left as is so that it could be a drop-in replacement. To keep things working, the C code was compiled to unsafe Rust using c2rust. It was then manually converted to safe Rust by manual refactoring.

I really don't know what to think at this point. On the one hand, 250k lines of assembly should mean that the 50k lines of high-level language has little overall effect no matter what it is - so it should work just as fast. On the other hand, the fact that the c2rust followed by manual refactoring worked at all is a big surprise and, yes, I can see that you might lose some performance there.

rustbanner1

The report on the project states that the approach was good because it allowed an incremental approach and the tests could still be used to validate each step. The estimate was that it would take 7 programmer months, but in fact it took 20 programmer months with a team of three who weren't codec specialists and discovered that Rust had its challenges:

"We encountered various challenges due to the mismatch between C and safe Rust patterns. Lifetime management required understanding the existing codebase in great detail, but we did not find that lifetimes and borrows were the most challenging issues. Rust thread safety, which makes sharing mutable data across worker threads difficult, was a poor fit for the dav1d threading model which shares almost all data implicitly between threads. Memory ownership and buffer pointers were further important sources of difficulty, as well as unions and other unsafe C patterns."

At the end of the day the conclusion was:

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.

There’s just one problem—it’s not quite as fast as the C version. We want to change that and we need your help.

Our Rust-based rav1d decoder is currently about 5% slower than the C-based dav1d decoder (the exact amount differs a bit depending on the benchmark, input, and platform). This is enough of a difference to be a problem for potential adopters, and, frankly, it just bothers us.

It bothers them enough to offer the aforementioned $20,000 to get it fixed. There are various rules that you have to adhere to if you want to get the payout, but personally I'd steer clear of this offer as the work needed is likely to be such that the going rate might be lower than $1 per hour. There is a lot of code in this project and 5% speed loss is a small hit that is probably due to the bounds checking used by Rust to make sure we don't get memory overruns. Or it could be something boring like the assembler Rust interface.

This isn't a Rust program designed and implemented from scratch with Rust at the forefront of the process. This is an automatically converted manual patch-up of a big code base. Personally I think a hit of just 5% proves Rust is a contender and snide comments that imply that if it is so good why do we need $20,000 to fix it are simply out of place.

rust

More Information

$20,000 rav1d AV1 Decoder Performance Bounty

Related Articles

Rust Celebrates 10 Years Since Version 1.0

Rust And C++ Should Be Friends?

The Feds Want Us To Move On From C/C++

DARPA Wants All C Converted To Rust

Is Rust Safe?

Rust Twice As Productive As C++

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Remembering Bill Atkinson
10/06/2025

Bill Atkinson, who pioneered the idea and implementation of the graphical user interface at Apple in the 1970s and 80s and also brought us HyperCard, died of pancreatic cancer on June 5, 2025 at  [ ... ]



Apache Syncope 4 Adds Live Sync
12/06/2025

Apache Syncope 4.0 Notturno has been released, with improvements including live sync,  OpenFGA integration, and a reworked persistence layer. Apache Syncope is an Open Source IAM (Identity A [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

 

 

Last Updated ( Monday, 19 May 2025 )