3 ms·
> When you need efficient trees or graphs (I doubt any non-trivial software doesn’t need at least one of them), unsafe code is the only reasonable choice. To n
by pcwalton 2y ago
> When you need efficient trees or graphs (I doubt any non-trivial software doesn’t need at least one of them), unsafe code is the only reasonable choice.
To name one example, the AnimationGraph in Bevy is implemented with petgraph, which is built using adjacency lists, and doesn't use any unsafe code in any of the parts that we use. It is very high-performance, as animation evaluation has to be.
- Const-me 2y ago> It is very high-performance, as animation evaluation has to be Are you sure evaluating these animations is performance critical? I doubt games have enough data to saturate a CPU core doing that. Screens only have 2-8 megapixels; animated objects need to be much larger than 1 pixel. If you animate bones for skeletal animation that’s still not much data to compute because real life people have less than 256 bones. You don’t need much more than that even if your models have fancy manually-animated clothes.
- refulgentis 2y ago> Are you sure evaluating these animations is performance critical? Isn't this obviously true? A key part of UI work is avoiding "jank", which commonly refers to skipped frames. > I doubt games have enough data to saturate a CPU core doing that. Got a bit lost here: games? > Screens only have 2-8 megapixels. 4 bytes per pixel, 32 MB/frame. 120 frames / sec = 8 ms/frame. 3.84 GB/second. > animated objects need to be much larger than 1 pixel. Got lost again here. In general, I'm lost. First, there's a weak claim that all performant data structures in Rust must use unsafe code. I don't think the author meant all performant data structures must use unsafe code. I assume they meant "a Rust data structure with unsafe code will outperform an equivalent Rust data structure with only safe code" Then, someone mentions a 3D renderer, written in Rust, is using a data structure with only safe code. I don't understand how questioning if its truly performant, then arguing rendering 3D isn't that hard, is relevant.
- Const-me 2y ago> Isn't this obviously true? To an extent sure, but we’re talking about low level micro-optimizations. Games don’t animate individual pixels. I don’t think animating 1000 things per frame gonna saturate a CPU core doing these computations, which means the code doing that is not actually performance critical. > Got a bit lost here: games? I searched the internets for “Bevy Engine” and found this web site https://bevyengine.org/ https://bevyengine.org/ which says “game engine”. I wonder is there another Bevy unrelated to games? > 3.84 GB/second In modern games none of that bandwidth is processed on CPU. Games use GPU for that, which don’t run Rust. > there's a weak claim that all performant data structures in Rust must use unsafe code Weak claim? Look at the source code of data structures implemented by Rust standard library. You will find unsafe code everywhere. When you need custom data structures instead of merely using the standard ones you will have to do the same, because safe Rust is fundamentally limited in that regard.
- steveklabnik 2y ago> Look at the source code of data structures implemented by Rust standard library. You will find unsafe code everywhere. This is survivorship bias: one of the criteria back in the day for “should this go in the standard library” was “is it a data structure that uses a lot of unsafe?” because it was understood that the folks in the project would understand unsafe Rust better than your average Rust programmer. These days, that isn’t as true anymore, but back then, things were different.
- refulgentis 2y ago> I don’t think animating 1000 things per frame gonna saturate a CPU core doing these computations Oh, my sweet summer child. :) > In modern games none of that bandwidth is processed on CPU. Games use GPU for that, which don’t run Rust. So is your claim that OP is making up stuff about running code on the CPU because its a 3D engine? Also, why mention megapixels if you think it's irrelevant? :) > Weak claim? "_all_ performant data structures in Rust _must_ use unsafe code" is a long tail reading of the original comment. If that was the intent, it is a weak claim, because we can observe many memory-safe languages and runtimes and have performant data structures. (minecraft was written in Java, years and years ago!) > Look at the source code of data structures implemented by Rust standard library. This is the bailey, which was directly covered in the previous comment. The motte was "all performant data structures in Rust must use unsafe code" Here, the bailey, steelmanning as strongly as possible, is "data structures with unsafe code are more performant than ones without", which was directly said in the comment you are replying to. In addition to the swapping, this is a picture-perfect replication of the bomber with holes on it meme, as the other reply notes.