Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I stole these graphs for a branch of that thread ffmpeg started on twitter. The one where they were flaming rav1d vs dav1d performance to attack Rust generally.

I don't like the RiiR cult. I do like smart use of a safer language and think long-term it can get better than C++ with the right work.



I'm the person who is running the rav1d bounty, also involved with the Rustls project.

In many (most?) situations I think Rust is effectively as fast as C, but it's not a given. They're close enough that depending on the situation, one can be faster than the other.

If you told me I had to make a larger and more complex piece of code fast though, I'd pick Rust. Because of the rules that the Rust compiler enforces, it's easier to have confidence in the correctness of your code and that really frees you up when you're dealing with multi-threaded or algorithmic complexity. For example, you can be more confident about how little locking you can get away with, what the minimum amount of time is that you need to keep some memory around, or what exact state is possible and thus needs to be handled at any given time.

There are some things that make rav1d performance particularly challenging. For example - unlike Rustls, which was written from the start in Rust, rav1d is largely the result of C to Rust translation. This means the code is mostly not idiomatic Rust, and the Rust compiler is generally more optimized for idiomatic Rust. How much this particular issue contributes to the performance gap I don't know, but it's a suspect and to the extent that it's worth pursuing, one would probably want to figure out where being idiomatic matters most instead of blanket rewriting everything.


> I don't like the RiiR cult.

For certain types of people, Rust has a way of just feeling better to use. After learning Rust I just can't imagine choosing to use C or C++ for a future project ever again. Rust is just too good.


Choosing Rust for new projects is very different than trying to rewrite an existing codebase with thousands of hours poured into it. Or worse, demanding that someone else do that for you for free.


People keep saying this. But in my experience, directly porting code from one language to another is much easier that people think. I can do maybe about 500 lines per day depending on the language similarity. ChatGPT is great for doing a first pass - though it will add small, subtle bugs in the process.

I’m not arguing that we should rewrite everything in rust. C and C++ are fine languages. But sometimes it really is better to just have your code in a different language rather than deal with FFI. For example, I have some collaborative text editing code in rust and recently I just ported the whole thing to typescript, because it’s just straight out easier to use in a browser that way, compared to dealing with a wasm bundle.

I think the big mistake people make when rewriting into a different language is doing a refactor at the same time. This is the wrong way to go about it. First port directly the code you have. Then port your tests and get them passing in the new language. Then refactor. Obviously there’s always some language differences - but ideally you can confine differences within modules, and keep most of the module boundaries intact through the rewrite. You can also refactor before translating your code. If I were porting something to rust that wouldn’t pass the borrow checker, this is probably what I’d do. First refactor everything to make the borrow checker happy - so for example, make sure your structs / classes are in a strict tree. Then get tests passing. Translate between languages and cleanup.

If you approach it like that, rewriting code is a largely mechanical process. It really takes a lot less time than people think to translate code, since you don’t actually have to understand every single line to do it correctly. So the time taken scales based on the number of lines of code. Not the number of hours it took to write! And then, if you want to refactor your new program at the end, go for it.


500 lines a day feels very much on the low side to me, for most projects. That’s around one line per minute. Yeah, there are definitely parts where you have to go a lot slower, but also there are plenty of lines that take 0–10 seconds.

Going from Rust to TypeScript will normally be pretty easy—though if things like numeric and bytewise manipulations are involved, it can be tough. Going from TypeScript to Rust will often be easy, but also often be fiendishly difficult to do without refactoring a lot, due to ownership model differences.

Occasionally I’ve chosen to do a refactoring in the source language first, and then port that. That can work decently, though it depends so much on exactly what the changes are and why they are, which is often to do with which two languages are involved.


500 lines a day feels about right taking the whole project into consideration. I ported a physics engine from C to Javascript a decade or so ago. Once I was in the swing of it, I did a lot more than 500 lines a day too. But I also spent a few days reading the original code. And I tweaked how I wanted to represent everything in javascript - which slowed me down. I should have just ported it directly, then refactored afterwards. And I spent a few days at the end tracking down some bugs that snuck in. In retrospect, typescript would have been a better choice. But I hadn't learned it yet.

The best days I ported maybe 1500 lines. On the "worst" days I did 0 lines. In all, 500 lines a day feels like the right ballpark for this sort of work.


> ChatGPT is great for doing a first pass - though it will add small, subtle bugs in the process.

Kill it with fire.


Downvoters: The whole point of Rust is avoiding defects due to programmer mistakes. Why would you use Rust, but then outsource the programming to a known-bad programmer/plagiarizer.


Isn’t that exactly why

If rust avoids defects due to programmer mistakes, then throwing a shitty programmer at it is functionally safe (or safer than otherwise) because their shitty code won’t compile. So worst case is they don’t do any harm, and best case is free cheap labor


Rust only prevents/discourages some classes of programmer mistakes.

But presumably your you want to reduce all of the mistakes.

Rust won't prevent/discourage a lot of the other classes of mistake that a bad programmer is creating.


Sure but generally speaking, the safer the language/model/api, the more likely you can get away with AI generated code.

Rust having more powerful modeling tools than the usual language sales it more viable to use crappier programmers, not less.

Obviously if your goal is perfection, then only hire programmers capable of writing perfection. If you’re making the trade-off of cheaper/junior resources and putting more effort into testing/api design/type design/code review to help defend against the inevitable errors, then your genai code fits neatly into the same equation


Yes, those are different experiences.

But assuming you're experienced with Rust, porting something is actually both easy and enjoyable.

Porting something as your first Rust project is going to end up like a dirty hybrid.

It's an excellent learning opportunity, but it will not leave a good showcase of Rust.


Yeah it depends on the project I think. There have been quite a lot of successful rewrites of large projects into Rust. For example Fish and svgr.


Rewriting could also make sense if there is a chance to improve the architecture based on the experience with the existing codebase. Something that would otherwise be impossible to even consider.


I feel similarly for most stuff. I just see a difference between “I like rust and enjoy using it for stuff bc of its advantages” and “rewrite the entire systems programming world in rust, also I will be bitchinf anytime someone releases something not written in rust, opening gh issues asking why it wasn’t, etc.”




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: